ConsultancyProject1_Auslast.../README.md

95 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2024-07-06 19:49:36 +02:00
# Web Scraper e-domizil.ch
2024-07-06 20:08:04 +02:00
Das Repository enthält einen auf [Laravel (Version 10.x)](https://laravel.org) basierender Web Scraper für die Plattform e-domizil.ch.
2024-02-27 20:32:02 +01:00
2024-07-06 19:49:36 +02:00
## Installation
2024-07-06 20:08:04 +02:00
> :warning: Vorbedingungen für die Installation sind die folgenden
- [git](https://git-scm.com/) ist auf dem System installiert.
- [composer](https://getcomposer.org/) ist auf dem System verfügbar.
- [Server Requirements](https://laravel.com/docs/10.x/deployment#server-requirements) sind erfüllt.
2024-07-06 19:49:36 +02:00
2024-07-06 20:08:04 +02:00
### 1. Repository klonen
Das Repository an den gewünschten Installationsort klonen:
2024-07-06 19:49:36 +02:00
```bash
git clone https://gitea.fhgr.ch/dianigionath/ConsultancyProject1_Auslastungsmodellierung.git`
2024-07-06 20:08:04 +02:00
```
### 2. Installation via Composer
Mittels Composer die Installation der Applikation vornehmen:
2024-07-06 19:49:36 +02:00
```bash
php composer install
```
2024-07-06 20:08:04 +02:00
### 3. Enviroment Konfigurieren
Eine Kopie der Datei .env.example nach .env erstellen und den Dateiinhalt bez. Datenbankverbindung anpassen:
2024-07-06 19:49:36 +02:00
```bash
cp .env.example .env`
```
2024-07-06 20:08:04 +02:00
Bsp. für Verbinung zu einer SQLite Datenbank:
2024-07-06 19:49:36 +02:00
```yaml
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
```
2024-07-06 20:08:04 +02:00
### 4. Datenbank initialisieren
Mittels Artisan Console die Datenbank initialisieren:
2024-07-06 19:49:36 +02:00
```bash
php artisan migrate
```
Erwartete Ausgabe:
```bash
WARN The SQLite database does not exist: /home/gio/database_test.sqlite.
┌ Would you like to create it? ────────────────────────────────┐
│ Yes │
└──────────────────────────────────────────────────────────────┘
INFO Preparing database.
Creating migration table ...................................................................................... 31ms DONE
INFO Running migrations.
0001_01_01_000000_create_users_table .......................................................................... 57ms DONE
0001_01_01_000001_create_cache_table .......................................................................... 18ms DONE
2019_12_14_000001_create_personal_access_tokens_table ......................................................... 36ms DONE
2024_03_15_142227_create_regions_table ........................................................................ 10ms DONE
2024_03_15_142228_create_seeds_table .......................................................................... 18ms DONE
2024_03_15_142257_create_properties_table ..................................................................... 17ms DONE
2024_03_15_142550_create_extractions_table .................................................................... 10ms DONE
2024_03_15_142625_create_exceptions_table ..................................................................... 10ms DONE
2024_03_15_162023_create_jobs_table ........................................................................... 18ms DONE
2024_04_08_115153_create_failed_jobs_table .................................................................... 32ms DONE
```
2024-07-06 20:08:04 +02:00
### 5. Regionen hinzufügen
Gewünschte Region(en) mittels Artisan Console hinzufügen:
2024-07-06 19:49:36 +02:00
```bash
php artisan scraper:add-region
```
Mögliche erwartete Ausgabe:
```bash
Type in desired region:
> Davos
Choose desired region:
[5460aea91d044] Davos
[5390628eeaa24] Davos Davos Platz
[5460adf3d7913] Davos Clavadel
[565847a969c59] Prättigau/Davos
[5460adf87857d] Davos Wolfgang
[5460adf8f3e46] Davos Monstein
> Davos
New Region created {"name":"Davos","updated_at":"2024-07-06T17:24:09.000000Z","created_at":"2024-07-06T17:24:09.000000Z","id":1}
New Seed added {"uri":"https:\/\/www.e-domizil.ch\/search\/5460aea91d044?_format=json","region_id":1,"updated_at":"2024-07-06T17:24:09.000000Z","created_at":"2024-07-06T17:24:09.000000Z","id":1}
```
2024-07-06 20:08:04 +02:00
### 6. Cronjobs
Zum Schluss sind Cronjobs einzurichten, welche den Webscraper regelmässig ausführen
#### Cronjonb: Jobs
2024-07-06 19:49:36 +02:00
Alle drei Tage um 02:00 die Scraping Jobs erstellen:
```bash
0 2 */3 * * /usr/local/bin/php ConsultancyProject1_Auslastungsmodellierung/artisan scrape:jobs
```
2024-07-06 20:08:04 +02:00
#### Cronjonb: Queue Worker
2024-07-06 19:49:36 +02:00
Jeden Tag alle drei Stunden zwischen 04:00 bis 23:00 mit einer zufälligen Verzögerung bis zu einer Stunde den Queue Worker für das Abarbeiten von 250 Jobs ausführen.
```bash
0 4,7,9,11,13,15,17,19,21,23 * * * sleep $((RANDOM \% 60))m ; /absolute/path/to/bin/php /absolute/path/to/artisan queue:work --max-jobs=250 --stop-when-empty --max-time=7200
```