gendesign/tradein-mvp/backend/app/services
lekss361 0c53108d7d feat(tradein): in-app scheduler — UI-managed schedule (replaces SSH crontab)
Background scheduler в FastAPI lifespan: each tick (60s) checks scrape_schedules
table, triggers city sweep run если due (next_run_at <= NOW() + enabled + no
running run), recomputes next_run_at для следующих суток в random время в окне.

- 052_scrape_schedules.sql: NEW table (source, enabled, window_start/end_hour UTC,
  default_params jsonb, last_run_id, last_run_at, next_run_at, updated_at).
  Seed: 'avito_city_sweep' enabled, window 2-5 UTC (05:00-08:00 МСК).
- scheduler.py NEW:
  * compute_next_run_at(start, end) — random datetime в окне для +1 day. Cross-midnight OK.
  * scheduler_loop() — tick каждые 60s
  * get_due_schedules / has_running_run / trigger_avito_city_sweep_run
  * reap_zombies() — runs running > 6h без heartbeat → status='zombie'
- main.py: FastAPI lifespan launches scheduler_task; clean shutdown через cancel
- admin.py: 2 endpoints
  * GET  /admin/scrape/schedules — list all (now single row, extensible)
  * PUT  /admin/scrape/schedules/{source} — update config (enabled, window, params)
    + auto-recompute next_run_at
- schemas/trade_in.py: ScheduleConfig + ScheduleConfigUpdate
- tests/test_scheduler.py: 6 offline tests (normal window, cross-midnight, 1h window,
  future check, timezone-aware check)

UI: frontend PR добавит секцию 6 на /scrapers/avito (parallel PR).
Cron-script deploy/avito-city-sweep.sh остаётся как backup, opt-in.
2026-05-23 17:49:00 +03:00
..
exporters fix(tradein): security hotfix — C-3 config default + C-4 empty estimate persist + C-6 PDF URL allowlist (#435) 2026-05-23 09:38:23 +00:00
matching feat(tradein): cross-source matching service (3-tier: cadastr / fingerprint / geo / composite) (#470) 2026-05-23 14:12:16 +00:00
scrapers feat(tradein): city sweep — auto ЕКБ pipeline (#477) 2026-05-23 14:38:07 +00:00
__init__.py feat: add tradein-mvp subproject (Trade-In Estimator под /trade-in) 2026-05-21 00:25:39 +03:00
brand.py feat: add tradein-mvp subproject (Trade-In Estimator под /trade-in) 2026-05-21 00:25:39 +03:00
cian_session.py feat(tradein): cian_session cookies management + admin endpoints (Wave 4 Worker A) (#457) 2026-05-23 13:22:00 +00:00
estimator.py feat(tradein): estimator — Cian Valuation as on-demand 7th source (Stage 9) (#476) 2026-05-23 14:29:52 +00:00
geocoder.py fix(tradein): map-picker подставляет уличный адрес, а не название POI 2026-05-22 13:32:39 +05:00
house_metadata.py feat(tradein): кадастр зданий как источник house_metadata (#393) 2026-05-22 10:54:42 +05:00
scheduler.py feat(tradein): in-app scheduler — UI-managed schedule (replaces SSH crontab) 2026-05-23 17:49:00 +03:00
scrape_pipeline.py feat(tradein): city sweep — auto ЕКБ pipeline (#477) 2026-05-23 14:38:07 +00:00
scrape_runs.py feat(tradein): city sweep — auto ЕКБ pipeline (#477) 2026-05-23 14:38:07 +00:00