Fix exact-time calendar alerts by adding scheduler grace window

This commit is contained in:
code-quad3 2026-05-13 03:42:21 +00:00
parent 998c86a52b
commit cb179ddc30
2 changed files with 4 additions and 2 deletions

View file

@ -696,6 +696,7 @@ class CalendarEventTable:
self,
now_ns: int,
default_lookahead_ns: int,
grace_ns: int = 0,
db: Optional[AsyncSession] = None,
) -> list[tuple[CalendarEventModel, Optional[str]]]:
"""Events starting between now and now + lookahead, for alert processing.
@ -716,7 +717,7 @@ class CalendarEventTable:
.outerjoin(UserRow, UserRow.id == CalendarEvent.user_id)
.filter(
CalendarEvent.is_cancelled == False,
CalendarEvent.start_at >= now_ns,
CalendarEvent.start_at >= now_ns - grace_ns,
CalendarEvent.start_at <= upper,
)
)

View file

@ -501,9 +501,10 @@ async def _check_calendar_alerts(app) -> None:
now_ns = int(time.time_ns())
default_lookahead_ns = CALENDAR_ALERT_LOOKAHEAD_MINUTES * 60 * 1_000_000_000
grace_ns = SCHEDULER_POLL_INTERVAL * 1_000_000_000
async with get_async_db() as db:
upcoming = await CalendarEvents.get_upcoming_events(now_ns, default_lookahead_ns, db=db)
upcoming = await CalendarEvents.get_upcoming_events(now_ns, default_lookahead_ns,grace_ns=grace_ns, db=db)
if not upcoming:
return