perf: gate deadline reminder polling (Closes #717)
CI / lint (pull_request) Failing after 1m27s
CI / build-release (pull_request) Has been skipped
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy committed 2026-08-13 07:23:05 +00:00
1 parent fc79e4523d
commit 8f0df3d393
4 files changed
+98 -3

No files matched your search

+6 -1
View File
@@ -106,6 +106,9 @@ async def _push_channel_loop(dispatch, *, interval: float) -> None:
async def _push_poll_loop() -> None:
interval = max(5.0, float(os.getenv("STACKCHAIN_PUSH_POLL_SECONDS", "30")))
deadline_interval = max(
60.0, float(os.getenv("STACKCHAIN_DEADLINE_POLL_SECONDS", "600"))
)
send_timeout = max(
1.0, float(os.getenv("STACKCHAIN_PUSH_SEND_TIMEOUT_SECONDS", "10"))
)
@@ -145,7 +148,9 @@ async def _push_poll_loop() -> None:
channel_tasks = (
asyncio.create_task(_push_channel_loop(dispatch_unread, interval=interval)),
asyncio.create_task(_push_channel_loop(dispatch_deadlines, interval=interval)),
asyncio.create_task(
_push_channel_loop(dispatch_deadlines, interval=deadline_interval)
),
)
try:
done, _pending = await asyncio.wait(
+15 -2
View File
@@ -289,10 +289,23 @@ async def _dispatch_deadline_reminders_unlocked(
devices = await asyncio.to_thread(store.deadline_reminder_devices)
if not devices:
return 0
current = now or datetime.now(timezone.utc)
eligible_devices = []
for device in devices:
try:
local_now = current.astimezone(ZoneInfo(device.timezone))
except ZoneInfoNotFoundError:
continue
if (
local_now.hour >= device.reminder_hour
and device.delivered_local_day != local_now.date().isoformat()
):
eligible_devices.append(device)
if not eligible_devices:
return 0
snapshot = await assigned()
if snapshot.get("complete") is False:
return 0
current = now or datetime.now(timezone.utc)
due_cutoff = current + timedelta(hours=48)
due_count = 0
for item in snapshot.get("items", []):
@@ -356,6 +369,6 @@ async def _dispatch_deadline_reminders_unlocked(
return 1
results = await asyncio.gather(
*(dispatch_device(device) for device in devices), return_exceptions=True
*(dispatch_device(device) for device in eligible_devices), return_exceptions=True
)
return sum(result for result in results if isinstance(result, int))