Auto-recheck parity after scrape + manual Recheck button + faster badge
Parity logic: - Extract _fetch_latest_alerts() and _upsert_alerts() helpers so the alert upsert loop is no longer duplicated between the daily job and per-date runs - Add run_parity_check_for_date(date) which runs the full comparison + alert upsert for a single date Scraper integration: - _safe_parity_recheck(date) wrapper (never raises) called after each successful date in both search-results and hotel-page workers; hotel-page mode waits until all hotels for the date are done before rechecking API: - POST /competitors/parity/check-date?rate_date=YYYY-MM-DD for manual recheck Frontend: - Recheck button on every parity alert row (all statuses); invalidates alerts list and badge count on success - parity-alert-count badge polls every 15s (was 60s) so new alerts from the scheduled job or post-scrape rechecks appear quickly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8a80c66a3b
commit
cab1a39503
5 changed files with 146 additions and 66 deletions
|
|
@ -4,7 +4,7 @@ Booking.com rate scraping, hotel management, and competitor comparison
|
|||
"""
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import date, datetime, timedelta
|
||||
from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks
|
||||
from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import text
|
||||
from pydantic import BaseModel
|
||||
|
|
@ -1042,6 +1042,18 @@ async def trigger_parity_check(
|
|||
return await loop.run_in_executor(None, run_parity_check)
|
||||
|
||||
|
||||
@router.post("/parity/check-date")
|
||||
async def trigger_parity_check_for_date(
|
||||
rate_date: date = Query(..., description="Date to recheck (YYYY-MM-DD)"),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Recheck parity for a single date using the latest scraped rates."""
|
||||
import asyncio
|
||||
from jobs.check_rate_parity import run_parity_check_for_date
|
||||
loop = asyncio.get_event_loop()
|
||||
return await loop.run_in_executor(None, run_parity_check_for_date, rate_date)
|
||||
|
||||
|
||||
# ============================================
|
||||
# PARITY ALERTS
|
||||
# ============================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue