fix(scheduler): trumpstruth poller never fires — APScheduler bug

next_run_time=None means "paused", not "default". The fallback poller was
registered but never triggered, leaving the system on CNN archive only.
Set explicit start time = now + half the poll interval so the two pollers
offset and don't hit upstream simultaneously.

Verified via /api/health/deep: trumpstruth.last_poll was null on the live
server before this fix despite the poller having been deployed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
k
2026-05-08 15:00:54 +08:00
parent 747158b5ed
commit b5e7c82b51
+6 -1
View File
@@ -69,6 +69,11 @@ async def lifespan(app: FastAPI):
# same external_id hash, so dedup is automatic. Whoever sees the post # 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 # first wins. Offset by half the interval so the two pollers don't
# hammer the network at the same instant. # 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( _scheduler.add_job(
poll_trumpstruth, poll_trumpstruth,
"interval", "interval",
@@ -77,7 +82,7 @@ async def lifespan(app: FastAPI):
id="trumpstruth_poll", id="trumpstruth_poll",
max_instances=1, max_instances=1,
coalesce=True, coalesce=True,
next_run_time=None, # APScheduler will pick a fresh slot next_run_time=_dt.now(_tz.utc) + _td(seconds=offset),
) )
_scheduler.start() _scheduler.start()
logger.info( logger.info(