gendesign/tradein-mvp/ops/systemd/README.md
bot-backend 639d3b0cea
All checks were successful
Deploy Trade-In / deploy (push) Successful in 36s
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / build-browser (push) Has been skipped
Deploy Trade-In / test (push) Successful in 30s
Deploy Trade-In / build-backend (push) Successful in 42s
feat(tradein): systemd timer scheduler — trigger script + units + SCHEDULER_ENABLE flag (#581)
Co-authored-by: bot-backend <bot-backend@gendsgn.local>
Co-committed-by: bot-backend <bot-backend@gendsgn.local>
2026-05-31 16:53:38 +00:00

57 lines
1.6 KiB
Markdown

# TradeIn systemd scrape trigger
Replaces the in-app asyncio scheduler with a systemd timer that calls the admin API every 60s.
## Install
Run as root on the VPS after deploy:
```bash
cd /opt/gendesign/tradein-mvp/ops/systemd
bash install.sh
```
`install.sh` copies the unit files to `/etc/systemd/system/`, reloads systemd, and
enables + starts the timer.
## Environment variables
Create `/etc/tradein/trigger.env` before enabling the timer:
```ini
# psycopg v3 connection string (postgresql://... or postgresql+psycopg://...)
TRADEIN_DATABASE_URL=postgresql://tradein:<password>@localhost:5432/tradein
# Admin username from roles.yaml with role=admin — passed as X-Authenticated-User header
TRADEIN_ADMIN_TOKEN=admin
# Backend base URL (no trailing slash). Default: http://localhost:8000
TRADEIN_API_BASE=http://localhost:8000
```
## Diagnostic commands
```bash
# Follow live timer logs
journalctl -u tradein-scrape-trigger -f
# List all active timers and next trigger times
systemctl list-timers
# Check timer status
systemctl status tradein-scrape-trigger.timer
# Check last service run
systemctl status tradein-scrape-trigger.service
# Manual one-shot trigger (for testing)
systemctl start tradein-scrape-trigger.service
```
## Notes
- The script uses `flock` on `/var/run/tradein-trigger.lock` to prevent overlapping
runs if the previous invocation is still running.
- Sources without a dedicated admin endpoint (e.g. `rosreestr_dkp_import`,
`listing_source_snapshot`) are logged as warnings and skipped. Set
`SCHEDULER_ENABLE=true` in the backend env to handle them via the in-app scheduler.