Introducing a new way to review your PRs.

Read the announcement

rajnandan1 / kener

Stunning status pages, batteries included!

View on GitHub

19 documents · Updated Nov 23, 2026

docs / queues-scheduling

Queues and scheduled work

Kener uses Redis-backed BullMQ queues to move monitoring work away from request handling and to connect each stage of the background flow. Scheduled jobs create monitor checks and maintain recurring operational work. Queue workers then execute checks, store their results, decide alerts, and send messages without making one process own the whole flow. This page expands the queue and scheduler part of the background runtime.

Background work model

The queue model separates work into small stages. A scheduler creates a job at the right time. A worker handles that job and can retry failed work. The shared queue setup gives workers a common Redis connection, a default retry policy, and a database context that is separate from the web request pool (src/…/q.ts• L13-52). Workers are created when their queue first receives work, so an unused queue does not consume worker capacity (src/…/q.ts• L44-51).

The main monitoring path is a handoff chain. A monitor scheduler sends a monitor to execution. Execution adds a result to response processing. Response processing writes the result and starts alert evaluation. Alert evaluation can create or resolve an alert and can start notification work.

This diagram shows how a scheduled monitor check moves through the background runtime.

flowchart LR
    MS[Monitor scheduler] --> EX[Monitor execution queue]
    EX --> RP[Monitor response queue]
    RP --> DB[(Monitoring history)]
    RP --> AL[Alerting queue]
    AL --> NI[Alert notifications]
    AL --> IN[Incident updates]
    IN --> SQ[Subscriber queue]
    SQ --> EQ[Email queue]
    NI --> EM[Email or provider delivery]

Monitor execution queue

The monitor execution queue runs a configured monitor for a minute boundary and prepares the status that the next stage will store. It applies maintenance and incident overlays after the check. It also combines the observed result with a configured default status and confirmation-threshold rules before it hands the result to response processing (src/…/monitorExecuteQueue.ts• L120-243).

The monitor scheduler is the normal source of these jobs. The minute runner passes the monitor and the start of the current UTC minute to the execution queue. Group monitors can add a short delay so their child checks do not all start at once (src/…/cron-minute.ts• L15-27). Jobs use a monitor-and-timestamp identity to avoid running the same scheduled check more than once (src/…/monitorExecuteQueue.ts• L254-280). The execution stage reads overlays for the job timestamp, so delayed work stays aligned with the minute it represents (src/…/monitorExecuteQueue.ts• L120-243).

Monitor response queue

The monitor response queue turns a prepared result into durable monitoring history. It stores the status, latency, result type, error text, and raw observed status. It also keeps certificate details in the latest-value cache when the result includes them. After the database write and cache update succeed, it passes the stored status to alert evaluation (src/…/monitorResponseQueue.ts• L37-75).

This boundary keeps recording and alert decisions downstream from the check itself. If the database write fails, the worker raises an error before the cache update or alert handoff, so the queue retry policy can try the full response job again (src/…/monitorResponseQueue.ts• L52-65).

Alerting queue

The alerting queue compares new monitor status with each active alert configuration. It supports status, latency, and uptime conditions. A condition must meet its configured failure threshold before an alert starts and its success threshold before an active alert resolves (src/…/alertingQueue.ts• L177-273).

When a condition changes state, the queue records the alert transition. It can create or close a linked incident, then sends the configured trigger messages for both the triggered and resolved states. Trigger messages can use email, webhook, Discord, or Slack delivery. The queue resolves active configurations for the monitor before it creates one job per configuration (src/…/alertingQueue.ts• L112-165, src/…/alertingQueue.ts• L289-349). Errors during alert evaluation or provider delivery are logged by the alert worker rather than returned for queue retry (src/…/alertingQueue.ts• L177-183, src/…/alertingQueue.ts• L275-277).

Notification queues

Notification work has two related paths. Alert triggers can send directly through the selected notification provider after alert evaluation. Subscription updates use a separate fan-out path that finds recipients first and then queues one email job per address.

Subscriber queue

The subscriber queue turns an incident or maintenance update into recipient-specific email work. It loads the subscription template, combines site values with event values, finds active subscribers for the event type, and sends one job for each subscriber to the email queue (src/…/subscriberQueue.ts• L30-75).

Incident comments are the single subscriber event for incident updates. This means an alert-created incident reaches incident subscribers through its comment rather than through a second alert-specific subscriber push (src/…/incidentController.ts• L424-450). Maintenance event creation uses the same subscriber queue for maintenance updates (src/…/maintenanceController.ts• L100-150).

References: src/…/subscriberQueue.ts• L30-75 src/…/incidentController.ts• L424-450 src/…/maintenanceController.ts• L100-150

Email queue

The email queue is the final asynchronous step for subscription email. Each job carries its template and variables for one recipient. The worker renders and sends the message through the configured email service, then rethrows send errors so failed jobs can retry (src/…/emailQueue.ts• L17-54).

Email rendering fills subject and body templates with alert, site, or subscription values. The delivery adapter uses either Resend or SMTP, and it rejects the job when neither service is configured (src/…/email_notification.ts• L10-76).

References: src/…/emailQueue.ts• L17-54 src/…/email_notification.ts• L10-76

Application scheduler

The application scheduler keeps the set of recurring monitor schedulers aligned with active monitor configuration. It runs every ten seconds. Each run adds schedulers for active monitors with a cron expression and removes schedulers that no longer match an active monitor (src/…/appScheduler.ts• L25-76, src/…/appScheduler.ts• L86-109).

The scheduler also refreshes maintenance event statuses as part of this reconciliation pass. This makes monitor scheduling and current operational-event state advance together (src/…/appScheduler.ts• L63-76).

Monitor scheduler

The monitor scheduler holds one recurring job per monitor. Each job uses the monitor's cron expression and runs the minute runner, which submits the actual check to the monitor execution queue (src/…/monitorSchedulers.ts• L19-36, src/…/monitorSchedulers.ts• L40-70).

The scheduler starts each monitor job immediately when it is created. Its worker concurrency scales with the number of active monitors, so the scheduling layer can submit work for the current monitor set without embedding check logic in the scheduler (src/…/monitorSchedulers.ts• L10-16, src/…/monitorSchedulers.ts• L59-70). A monitor scheduler identity includes the monitor tag and a hash of its current record. A changed monitor record therefore causes the application scheduler to replace the old recurring job (src/…/appScheduler.ts• L25-76).

Maintenance scheduler

The maintenance scheduler prepares future events for recurring maintenance records. It runs at startup and then once per hour. For each active recurring maintenance, it looks across the next seven days, creates missing event records, and leaves existing event times unchanged (src/…/maintenanceScheduler.ts• L21-78, src/…/maintenanceScheduler.ts• L81-106, src/…/maintenanceScheduler.ts• L138-165).

Recurring rules with a time zone keep their local wall-clock time when daylight-saving rules change. Rules without a time zone continue to repeat in UTC. The seven-day window includes an occurrence exactly at its end, while later occurrences wait for a later hourly run (src/…/maintenanceOccurrences.ts• L81-107, src/…/maintenanceScheduler.test.ts• L116-244).

Event creation also determines the event's current state and can publish a maintenance update to subscribers. One-time maintenance records do not use this recurring generation path because their event is handled when the maintenance is created (src/…/maintenanceScheduler.ts• L25-30, src/…/maintenanceController.ts• L100-150).

Cleanup scheduler

The cleanup scheduler protects monitoring history from unbounded growth. It runs at midnight in the process time zone, which is midnight UTC when the process uses TZ=UTC. It reads the site data-retention policy, uses a default of enabled retention for 90 days when the policy is absent or invalid, and deletes data older than the effective retention period (src/…/dailyCleanup.ts• L17-64, src/…/dailyCleanup.ts• L85-115).

The policy can disable cleanup. The scheduler then records a skipped result instead of deleting monitoring rows. A configured retention value is constrained to at least one day (src/…/dailyCleanup.ts• L47-64).

Startup and shutdown

Startup establishes the recurring application, maintenance, and cleanup schedulers. Queue workers are created when their queues first receive work, while monitor scheduling creates its worker when the scheduler queue is accessed (src/…/startup.ts• L7-12, src/…/monitorExecuteQueue.ts• L22-27, src/…/monitorSchedulers.ts• L10-16).

Shutdown closes scheduler and queue workers so they stop taking new jobs before the process exits. The runtime has separate shutdown entry points for the scheduler set and the notification and monitoring queue set (src/…/shutdown.ts• L1-11, src/…/shutdown.ts• L1-13). Shutdown closes workers but does not remove scheduler records from Redis, so recurring schedules remain available across process restarts (src/…/shutdown.ts• L1-11).

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to the monitor result shape must remain compatible across execution, response storage, cache updates, and alerting input.
  • A change to certificate result fields must preserve the latest-value cache contract. Otherwise current certificate state can disappear even when history is stored.
  • A change to alert trigger types or payload templates must preserve the matching provider path and the variables supplied to it.
  • A change to alert or incident notification ownership must preserve one subscriber event per incident comment. Otherwise alert-created incidents can send duplicate messages.
  • A change to recurring monitor identity must keep active-monitor reconciliation aligned with the scheduler IDs. Otherwise old monitor jobs can continue to run or new jobs can be skipped.
  • A change to queue job identity must preserve monitor-minute and alert-configuration deduplication. Subscriber and email jobs need explicit event IDs when one notification must represent one event.
  • A change to maintenance recurrence or event status must preserve the inclusive seven-day generation window and the notification path for newly created events. Time-zone rules must keep local wall-clock times across daylight-saving changes and keep UTC behavior when no time zone is set.
  • A change to email recipient handling must keep subscription delivery split into one recipient per email job.
  • A change to retention policy parsing must keep invalid or missing policy data safe and must not turn a disabled policy into deletion work.

Important failure modes

TriggerConsequenceGuard
A monitor response cannot be writtenThe result is not stored and cache or alert work does not run for that response jobThe response worker throws before the later handoffs so BullMQ can retry the job (src/…/monitorResponseQueue.ts• L52-65)
A monitor response is stored but its latest-value cache update failsAlert evaluation is not reached for that attemptThe response worker awaits the cache update before it pushes alert work (src/…/monitorResponseQueue.ts• L67-75)
An alert condition has not met its failure or success thresholdThe alert stays in its current state even when one new status looks affected or healthyThe alert worker checks consecutive status, latency, or uptime evidence before transition (src/…/alertingQueue.ts• L188-206, src/…/alertingQueue.ts• L239-271)
An alert trigger has an empty email recipient listThat trigger sends no messageThe alert worker skips the trigger when no usable address remains after parsing (src/…/alertingQueue.ts• L124-135)
An alert trigger has an unsupported type or its provider call failsThe alert job logs the error, later trigger work in that job does not run, and the failed alert job is not retriedAlert processing catches errors around the state and notification flow (src/…/alertingQueue.ts• L178-183, src/…/alertingQueue.ts• L275-277)
No active subscription template or recipient existsThe subscriber job fails for a missing template or ends without email work for an empty recipient setThe subscriber worker checks the template and treats an empty recipient list as a no-op (src/…/subscriberQueue.ts• L41-58)
Email service configuration is missing or a provider send failsThe email job cannot deliver the messageThe sender validates Resend or SMTP setup and rethrows errors for queue retry (src/…/email_notification.ts• L37-76, src/…/emailQueue.ts• L40-53)
A recurring maintenance event falls outside the generated windowThe event is not available until a later maintenance scheduler runThe scheduler runs at startup and every hour while generating the inclusive next seven days (src/…/maintenanceScheduler.ts• L36-48, src/…/maintenanceScheduler.ts• L152-164)
A recurring maintenance time zone is handled as UTCEvents move by an hour around daylight-saving changes or occur on the wrong local dayOccurrence generation applies the maintenance time zone to each recurrence and keeps UTC behavior only when no time zone is set (src/…/maintenanceOccurrences.ts• L81-107, src/…/maintenanceScheduler.test.ts• L116-163)
Retention policy data is invalidCleanup uses unsafe or unpredictable settingsPolicy parsing falls back to enabled 90-day retention and clamps the period to at least one day (src/…/dailyCleanup.ts• L29-50)
The process time zone is not UTCDaily cleanup runs at local midnight rather than midnight UTCThe scheduler has no time-zone setting. Deploy with TZ=UTC when UTC cleanup is required (src/…/dailyCleanup.ts• L17-64)

Key files

FileWhy to read it
src/…/q.tsShared queue and worker behavior, including Redis use, retries, and worker database context
src/…/monitorExecuteQueue.tsMonitor check handoff and the rules that shape a result before storage
src/…/monitorResponseQueue.tsResult persistence, latest-value updates, certificate cache fields, and the start of alert evaluation
src/…/alertingQueue.tsAlert threshold decisions, incident changes, and alert-trigger delivery across supported providers
src/…/subscriberQueue.tsSubscription lookup, template assembly, and recipient fan-out
src/…/emailQueue.tsFinal per-recipient email job and retry boundary
src/…/appScheduler.tsActive monitor reconciliation and recurring scheduler upkeep
src/…/monitorSchedulers.tsCron-based monitor job scheduling and dispatch to the minute runner
src/…/maintenanceScheduler.tsRecurring maintenance event generation and its seven-day look-ahead
src/…/maintenanceOccurrences.tsRecurrence timing in UTC or a maintenance time zone, including daylight-saving changes
src/…/maintenanceScheduler.test.tsContract checks for maintenance time zones, boundary times, and duplicate-free hourly runs
src/…/dailyCleanup.tsRetention policy and scheduled monitoring-data cleanup
src/…/startup.tsStartup order for recurring schedulers
src/…/shutdown.tsCoordinated close of monitoring and notification workers