[tradein][scrapers] Cian history backfill — переместить в scheduler #560

Closed
opened 2026-05-25 06:02:31 +00:00 by lekss361 · 1 comment
Owner

Сейчас

POST /api/v1/admin/scrape/cian-backfill-history — long-running background task, запускается руками.

Файл: backend/app/tasks/cian_history_backfill.py. State через scrape_runs, heartbeat, zombie через 6h.

Проблема

  • Если admin забыл триггернуть после redeploy → нет fresh price history.
  • listings_snapshots / offer_price_history сейчас пустые несмотря на schema (decision Decision_Cian_History_Valuation_Activation_May24 мерджили 4 PR, но automation не настроен).

Что сделать

  1. Добавить row в scrape_schedules:
    • source='cian_history_backfill'
    • окно: window_start_hour=2, window_end_hour=5 (Москва, низкая нагрузка на Cian)
    • default_params: {batch_size: 100, max_pages: 10, sources: ["valuation", "newbuilding"]}
  2. В services/scheduler.py добавить ветку if source == 'cian_history_backfill': run_cian_backfill(...) с тем же шаблоном что run_avito_city_sweep.
  3. Pre-check: verify_session() из cian_session.py → если cookies expired, помечаем run как failed, alert через GlitchTip (sentry capture_message).
  4. Checkpoint: после каждых 50 listings — UPDATE scrape_runs SET progress=.... Резюм по WHERE id > last_processed_id.

Acceptance

  • scrape_schedules WHERE source='cian_history_backfill' существует, enabled=true.
  • 24h не было ручного триггера → listings_snapshots пополняется (rowcount растёт).
  • Если рестарт во время backfill → следующий тик подхватывает с last checkpoint, не дублирует.

Refs

  • TODO в backend/app/tasks/cian_history_backfill.py:2houses не имеют cian_url/cian_zhk_url колонки (см. отдельный issue про PR #525).
## Сейчас `POST /api/v1/admin/scrape/cian-backfill-history` — long-running background task, запускается руками. Файл: `backend/app/tasks/cian_history_backfill.py`. State через `scrape_runs`, heartbeat, zombie через 6h. ## Проблема - Если admin забыл триггернуть после redeploy → нет fresh price history. - `listings_snapshots` / `offer_price_history` сейчас пустые несмотря на schema (decision `Decision_Cian_History_Valuation_Activation_May24` мерджили 4 PR, но automation не настроен). ## Что сделать 1. Добавить row в `scrape_schedules`: - `source='cian_history_backfill'` - окно: `window_start_hour=2`, `window_end_hour=5` (Москва, низкая нагрузка на Cian) - `default_params`: `{batch_size: 100, max_pages: 10, sources: ["valuation", "newbuilding"]}` 2. В `services/scheduler.py` добавить ветку `if source == 'cian_history_backfill': run_cian_backfill(...)` с тем же шаблоном что `run_avito_city_sweep`. 3. Pre-check: `verify_session()` из `cian_session.py` → если cookies expired, помечаем run как `failed`, alert через GlitchTip (sentry capture_message). 4. Checkpoint: после каждых 50 listings — `UPDATE scrape_runs SET progress=...`. Резюм по `WHERE id > last_processed_id`. ## Acceptance - `scrape_schedules WHERE source='cian_history_backfill'` существует, enabled=true. - 24h не было ручного триггера → `listings_snapshots` пополняется (rowcount растёт). - Если рестарт во время backfill → следующий тик подхватывает с last checkpoint, не дублирует. ## Refs - TODO в `backend/app/tasks/cian_history_backfill.py:2` — `houses` не имеют `cian_url`/`cian_zhk_url` колонки (см. отдельный issue про PR #525).
lekss361 added the
tradein
scrapers
automation
labels 2026-05-25 06:02:31 +00:00
Owner

Working on this in PR #630

Working on this in PR #630
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#560
No description provided.