feat(tradein): scraper_settings live-config + Yandex admin trigger endpoints #484
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#484
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/tradein-yandex-admin-backend"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Motivation
Backend foundation for the new Yandex admin scraper page (UI mirrors Avito at
tradein-mvp/frontend/src/app/scrapers/avito/page.tsx; frontend lands in a follow-up PR).User asked: "сделай страничку аналогичную авито только нужно добавить глобальный делэй для запросов что бы настройка работала на все запросы" → analogous Yandex page + one global delay knob that all 4 Yandex scrapers obey at runtime.
Changes
scraper_settingstable (mig 053)sourceBaseScraper.name(or umbrella alias)request_delay_secupdated_atdescriptionSeeded with single row
yandex= 5.0s — all 4 Yandex scrapers resolve to this umbrella key via_KEY_ALIASES.app/services/scraper_settings.py(new)get_scraper_delay(source: str) → float— 60s in-process cache, DB read on miss, hardcoded fallback on errorinvalidate_cache(source | None)— called by admin PUT to make change live without restart_KEY_ALIASESmapsyandex_detail/yandex_newbuilding/yandex_realty_nb/yandex_valuation→ umbrella"yandex"4 Yandex scrapers wired
Each now reads delay at
__init__time:Class-level
request_delay_sec = 5.0kept as last-resort fallback.5 new admin endpoints (
/api/v1/admin/...)/scraper-settings/scraper-settings/{source}/scrape/yandex-detail?offer_url=→ DetailEnrichment snapshot/scrape/yandex-newbuilding?slug=&id=&city=ekaterinburg→ ЖК snapshot/scrape/yandex-valuation?address=&offer_category=&offer_type=&page=→ house meta + history countAll POST triggers are read-only debug (no DB write — main production path goes through
/estimateper PR #473).Tests
Files
data/sql/053_scraper_settings.sqlapp/services/scraper_settings.pyapp/api/v1/admin.pyapp/services/scrapers/yandex_realty.pyapp/services/scrapers/yandex_detail.pyapp/services/scrapers/yandex_newbuilding.pyapp/services/scrapers/yandex_valuation.pytests/test_scraper_settings.pytests/test_yandex_scrapers_delay_wiring.pyTotal: 9 files, +509 / -3.
Follow-up
Frontend page (new
app/scrapers/yandex/page.tsx) — separate PR after this merges, so types/contracts are locked.Reviewer note
Reviewer: deep-code-reviewer — only merge after APPROVE.
Backend foundation for the Yandex admin scraper page (UI follows in next PR). scraper_settings (mig 053): - New table source PK + request_delay_sec numeric(5,2) + updated_at + description - Seeded with row 'yandex' = 5.0s (umbrella key for all 4 Yandex scrapers) scraper_settings.py (new): - get_scraper_delay(source) -> float, with 60s in-process cache + DB fallback - Yandex sub-scrapers (yandex_detail / yandex_newbuilding / yandex_valuation) resolve to umbrella 'yandex' key via _KEY_ALIASES - invalidate_cache(source | None) for admin PUT side-effect - Deferred SessionLocal import (_open_session helper) for unit-test compat 4 Yandex scrapers wired to load delay at __init__: - yandex_realty.py / yandex_detail.py / yandex_newbuilding.py / yandex_valuation.py - Class default bumped to 5.0; instance value overridden via get_scraper_delay(self.name) admin.py -- 5 new endpoints: - GET /scraper-settings list[ScraperSetting] - PUT /scraper-settings/{source} upsert + invalidate_cache - POST /scrape/yandex-detail offer_url= -> detail snapshot - POST /scrape/yandex-newbuilding slug=, id=, city=ekaterinburg -> JK snapshot - POST /scrape/yandex-valuation address=, offer_category=, offer_type=, page= -> house meta Tests: 10 + 4 = 14 new unit tests (loader cache/alias/error paths + scraper wiring). Ruff clean.Merged via deep-code-reviewer — verdict APPROVE.
Verified:
yandexMinor (non-blocking, follow-up):