Skip to content

Alerting: background scheduler runs due digests and alert evaluations #12

Description

@rupertgermann

Parent

#6

What to build

Nothing runs on a schedule today — digests and alert evaluations only happen when a user manually triggers them. Add a background scheduler: a single exported tick function runs due digests for all users and evaluates alert rules, and the framework instrumentation hook starts an interval that calls it. Environment variables control whether the scheduler is enabled and the interval length. The tick is idempotent and guarded against overlapping runs (a tick that is still running prevents the next from starting concurrently). The existing manual trigger endpoint remains unchanged for external-cron deployments.

Acceptance criteria

  • Calling the tick function delivers all due digests across users and records alert-rule evaluations
  • A digest that is not yet due is not delivered; calling the tick twice in a row does not double-deliver
  • Overlapping invocations are guarded: a second tick entered while the first is running returns without doing duplicate work
  • Scheduler enablement and interval come from environment configuration; disabled means no interval is started
  • The manual trigger endpoint still works as before
  • TDD: behavior covered at the exported tick-function seam (temporary database, globalThis.fetch swapped); the interval wiring in the instrumentation hook stays as untested glue; npm test green

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentTriaged and ready for an AFK agent to implement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions