31 lines
973 B
Python
31 lines
973 B
Python
"""notify-digest, every 5 minutes: send the daily digests whose time has passed (see notify/digest.py). Not
|
|||
|
|
pausable."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from ...feed.config import FeedSettings
|
||
|
|
from ...notify import digest
|
||
|
|
from . import Counts, JobContext, JobSpec, directory, reload_departments
|
||
|
|
|
||
|
|
EVERY_SECONDS = 5 * 60
|
||
|
|
|
||
|
|
|
||
|
|
def run(ctx: JobContext) -> Counts:
|
||
|
|
has = ctx.conn.execute("SELECT EXISTS (SELECT 1 FROM notification_outbox WHERE sent_at IS NULL)").fetchone()[0]
|
||
|
|
if not has:
|
||
|
|
return {"due": 0}
|
||
|
|
reload_departments(ctx.conn)
|
||
|
|
counts = digest.run_digest(ctx.conn, ctx.settings, directory(ctx), ctx.now_site())
|
||
|
|
if counts.get("failed"):
|
||
|
|
ctx.degrade(str(counts.get("error") or f"{counts['failed']} digest messages failed"))
|
||
|
|
return counts
|
||
|
|
|
||
|
|
|
||
|
|
def _cadence(_: FeedSettings, __: datetime) -> int:
|
||
|
|
return EVERY_SECONDS
|
||
|
|
|
||
|
|
|
||
|
|
SPEC = JobSpec(name="notify-digest", run=run, cadence=_cadence, pausable=False)
|