Add configurable 30-day NewBook rate rescrape on 2/4/6/12h intervals
Intraday rescrape jobs are distributed evenly between the main nightly run (05:20) and cover only the next 30 days — lightweight complement to the full 720-day nightly sweep. Interval is configurable from the Newbook tab in Settings and takes effect immediately without a container restart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7d0b7d2d3b
commit
078cb47b16
3 changed files with 238 additions and 1 deletions
|
|
@ -61,6 +61,53 @@ async def run_scheduled_direct_scrape():
|
|||
await loop.run_in_executor(None, run_scrape_all_direct)
|
||||
|
||||
|
||||
async def run_short_newbook_rescrape():
|
||||
"""Fetch next-30-day NewBook rates — lightweight complement to the full nightly run."""
|
||||
from jobs.fetch_current_rates import run_fetch_current_rates
|
||||
await run_fetch_current_rates(horizon_days=30)
|
||||
|
||||
|
||||
def _compute_rescrape_times(base_hour: int, base_minute: int, interval_hours: int) -> list:
|
||||
"""Return (hour, minute) tuples evenly spaced around the clock, excluding the base (main) run."""
|
||||
return [
|
||||
((base_hour + offset) % 24, base_minute)
|
||||
for offset in range(interval_hours, 24, interval_hours)
|
||||
]
|
||||
|
||||
|
||||
def apply_newbook_rescrape_schedule():
|
||||
"""Read config and (re)register 30-day NewBook rescrape jobs without a scheduler restart."""
|
||||
for job in list(scheduler.get_jobs()):
|
||||
if job.id.startswith('nb_rescrape_'):
|
||||
scheduler.remove_job(job.id)
|
||||
|
||||
interval_str = get_config_value('newbook_rescrape_interval_hours', '0')
|
||||
try:
|
||||
interval_hours = int(interval_str or '0')
|
||||
except ValueError:
|
||||
interval_hours = 0
|
||||
|
||||
if interval_hours not in (2, 4, 6, 12):
|
||||
logger.info("NewBook 30-day rescrape disabled")
|
||||
return
|
||||
|
||||
rates_hour, rates_minute = get_sync_time('newbook_current_rates', 5, 20)
|
||||
times = _compute_rescrape_times(rates_hour, rates_minute, interval_hours)
|
||||
|
||||
for i, (h, m) in enumerate(times):
|
||||
scheduler.add_job(
|
||||
run_short_newbook_rescrape,
|
||||
CronTrigger(hour=h, minute=m),
|
||||
id=f'nb_rescrape_{i}',
|
||||
replace_existing=True,
|
||||
)
|
||||
logger.info(
|
||||
f"NewBook rescrape: {len(times)} extra run(s) at {interval_hours}h intervals "
|
||||
f"(base {rates_hour:02d}:{rates_minute:02d}): "
|
||||
f"{[f'{h:02d}:{m:02d}' for h, m in times]}"
|
||||
)
|
||||
|
||||
|
||||
async def run_scheduled_parity_check():
|
||||
from jobs.check_rate_parity import run_parity_check
|
||||
import asyncio
|
||||
|
|
@ -159,6 +206,9 @@ def start_scheduler():
|
|||
scheduler.start()
|
||||
logger.info(f"Scheduler started: booking scrape at {scrape_hour:02d}:{scrape_minute:02d}, rates fetch at {rates_hour:02d}:{rates_minute:02d}, direct scrape at 06:00, parity check at 06:45, watchdog every 30m")
|
||||
|
||||
# 30-day NewBook rescrape — optional intraday refresh, interval from config
|
||||
apply_newbook_rescrape_schedule()
|
||||
|
||||
|
||||
def shutdown_scheduler():
|
||||
if scheduler.running:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue