diff --git a/app/main.py b/app/main.py index aa638ff..88d50a1 100644 --- a/app/main.py +++ b/app/main.py @@ -69,6 +69,11 @@ async def lifespan(app: FastAPI): # same external_id hash, so dedup is automatic. Whoever sees the post # first wins. Offset by half the interval so the two pollers don't # hammer the network at the same instant. + # Offset the fallback by half the interval so the two pollers don't hit + # upstream at the same instant. APScheduler treats next_run_time=None as + # "paused" (job never fires) — must be an actual datetime. + from datetime import datetime as _dt, timezone as _tz, timedelta as _td + offset = settings.truth_social_poll_seconds // 2 _scheduler.add_job( poll_trumpstruth, "interval", @@ -77,7 +82,7 @@ async def lifespan(app: FastAPI): id="trumpstruth_poll", max_instances=1, coalesce=True, - next_run_time=None, # APScheduler will pick a fresh slot + next_run_time=_dt.now(_tz.utc) + _td(seconds=offset), ) _scheduler.start() logger.info(