The four ways scheduled jobs fail, why error alerts miss the worst one, heartbeat and last-success metrics, run history tables, and the alert rules that catch a job that silently stopped running.

Scheduled jobs fail quietly: an API that breaks gets noticed within minutes because users hit it, while a nightly export that stopped running three weeks ago gets noticed when a customer asks where their report went.
Monitoring cron jobs comes down to watching for missing success rather than for errors, and this guide covers how to set that up.
Two of the four produce no error at all, which is why "alert on job errors" alone leaves the worst cases undetected.
The reliable pattern is to record when the job last succeeded and alert when that timestamp is older than it should be. The Prometheus guidance on batch jobs recommends exactly this: export the time of the last success and alert on its age, instead of trying to detect each failure type.
# Prometheus alert rule: the nightly export has not succeeded in 26 hours
- alert: NightlyExportStale
expr: time() - job_last_success_unixtime{job_name="nightly-export"} > 26 * 3600
for: 10m
labels:
severity: page
The margin matters: a job scheduled every 24 hours that takes up to an hour should alert after 26 hours, not 24. A hosted dead man's switch works the same way in reverse, with the job pinging a URL on success and the service alerting when pings stop. For jobs that run outside a long-lived process, the Pushgateway docs describe pushing the same metric at the end of each run.
Success alone does not catch a job that runs and does nothing, while recording counts per run, such as rows processed or emails sent, lets a second rule alert when a job that usually processes thousands of rows processes zero. A small job_runs table also gives support staff an answer to "did last night's export run" without reading logs:
CREATE TABLE job_runs (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
job_name text NOT NULL,
started_at timestamptz NOT NULL,
finished_at timestamptz,
status text NOT NULL, -- running, succeeded, failed, skipped
items integer,
error text
);
CREATE INDEX job_runs_name_started ON job_runs (job_name, started_at DESC);
A job that takes longer than its interval either overlaps itself or, with a lock, skips runs. Record duration on every run and alert when it exceeds a fraction of the interval, so the trend shows up before overlaps start. Schedulers handle missed runs differently: the Kubernetes CronJob controller records a warning when more than 100 schedules were missed and starts only the most recent one, so a long outage does not replay every missed run, which is usually what you want but worth knowing.
Best fit: a last-success metric with a staleness alert for every job, run records with item counts for jobs where zero output is suspicious, and duration tracking for jobs near their interval.
Encore brings infrastructure from code to scheduled work: a cron job is declared in Go next to the endpoint it calls, the Encore platform manages the schedule in deployed environments, and the Platform Dashboard lists each job's executions per environment. The last-success signal is a custom metric set at the end of each run:
Run in your terminal to get started locally.
package exports
import (
"context"
"time"
"encore.dev/cron"
"encore.dev/metrics"
"encore.dev/rlog"
"encore.dev/storage/sqldb"
)
var db = sqldb.NewDatabase("exports", sqldb.DatabaseConfig{Migrations: "./migrations"})
type JobLabels struct {
JobName string
}
var LastSuccess = metrics.NewGaugeGroup[JobLabels, int64]("job_last_success_unixtime", metrics.GaugeConfig{})
var ItemsProcessed = metrics.NewCounterGroup[JobLabels, uint64]("job_items_processed", metrics.CounterConfig{})
var _ = cron.NewJob("nightly-export", cron.JobConfig{
Title: "Export yesterday's orders to the warehouse",
Schedule: "0 2 * * *",
Endpoint: NightlyExport,
})
//encore:api private
func NightlyExport(ctx context.Context) error {
const job = "nightly-export"
var runID int64
if err := db.QueryRow(ctx,
`INSERT INTO job_runs (job_name, started_at, status) VALUES ($1, now(), 'running') RETURNING id`,
job).Scan(&runID); err != nil {
return err
}
n, err := exportOrders(ctx)
if err != nil {
rlog.Error("export failed", "err", err)
_, _ = db.Exec(ctx,
`UPDATE job_runs SET finished_at = now(), status = 'failed', error = $2 WHERE id = $1`, runID, err.Error())
return err
}
if _, err := db.Exec(ctx,
`UPDATE job_runs SET finished_at = now(), status = 'succeeded', items = $2 WHERE id = $1`, runID, n); err != nil {
return err
}
ItemsProcessed.With(JobLabels{JobName: job}).Add(uint64(n))
LastSuccess.With(JobLabels{JobName: job}).Set(time.Now().Unix())
return nil
}
// exportOrders writes yesterday's orders to the warehouse and returns how many it exported.
func exportOrders(ctx context.Context) (int, error) {
// Export logic goes here.
return 0, nil
}
Cron jobs do not run locally or in preview environments, so during development encore run starts Postgres and you call NightlyExport from the local development dashboard to check that it writes a job_runs row. In deployed environments the metrics can be forwarded to Grafana Cloud or Datadog, as described in the metrics integrations docs, where the staleness rule above becomes an alert.
An AI coding agent adding a new scheduled job can copy the same three lines that record the run and set the gauge, so every job ships with its monitoring instead of gaining it after the first silent failure.
Best fit: services with scheduled work where a missed run has a business cost, such as exports, billing and reminders.
Give every job a last-success metric and a staleness alert with a margin above its interval. Add run records with item counts for jobs where zero output would be a bug, track duration for jobs near their interval, and make jobs idempotent so a manual rerun after an alert is always safe.
Record the time of the last successful run, either as a metric or in a table, and alert when it is older than the schedule interval plus a margin. An error alert cannot fire for a job that never started, so the check has to look for the absence of success.
It is an external check that expects a ping from the job on every successful run and alerts when the ping does not arrive within the expected window. It catches failures, crashes and jobs that never started with a single rule.
Take a lock at the start of the run, for example a Postgres advisory lock with pg_try_advisory_xact_lock, and exit early if another run holds it. Record skipped runs so a job that is always overlapping shows up in monitoring.
The Platform Dashboard lists every cron job and its executions per environment. For alerting, set a last-success gauge from encore.dev/metrics at the end of each run, export metrics to Grafana Cloud or Datadog, and alert when the value goes stale.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.