Skip to content
PD
EN RU
AI Automation 8 min read

Your Cron Job Will Miss a Run: Scheduling Automations That Survive Real Life

Cron fires and forgets. Here is the slot-based scheduling pattern I use for parsers, AI digests and bots: catch-up rules, overlap rules, DST handling and alerts on silence.

PD

Pavel Duglas

AI Automation & MVP Architect

A client once asked me why their competitor price report had shown the same numbers for four days. The parser was fine. The proxies were fine. The server had rebooted during a provider maintenance window at 02:58, and the cron entry for 03:00 simply never happened. Cron does not remember. It does not apologize. It just waits for tomorrow at 03:00 and acts like nothing went wrong.

Most automations I build run on a schedule: nightly scrapes, morning AI digests, hourly lead enrichment, weekly billing reconciliation. The scheduling layer is usually the part people spend the least time on. It is also the part that fails the most quietly. This is the pattern I now use by default, and you can retrofit it onto an existing project in a day.

Why schedules fail without telling you

A schedule can fail in more ways than a crash. These are the ones I have actually hit in production:

  • The host was down at fire time. Reboots, deploys, a container restart loop. Classic cron has no catch-up. The run is just gone.
  • The hosted scheduler was late or skipped. Most managed cron features on CI platforms and serverless hosts are best-effort. Under load they fire minutes or hours late, and some disable schedules on repos with no recent activity.
  • The previous run was still going. Your hourly scraper takes 70 minutes on a bad day. Now two instances fight over the same proxy pool and the same rows.
  • Daylight saving time. A job at 02:30 local time does not exist one night a year and runs twice another night.
  • Everything fires at midnight. Ten jobs start at 00:00, all hit the same LLM provider, you get rate limited, half of them fail.
  • The run happened but was useless. The morning digest generated at 15:00 after a retry storm. Technically success. Practically garbage.

None of these show up as an error in your logs, because nothing errored. Something just did not happen, and absence is the hardest thing to monitor.

The core shift: schedule slots, not executions

Cron thinks in executions: at this moment, run this command. I think in slots: for every logical time a job should have run, there is a row in a database, and that row has a status.

A minimal table looks like this:

create table scheduled_runs (
  job_name     text not null,
  slot_at      timestamptz not null,
  status       text not null default 'pending',
  attempts     int not null default 0,
  lease_until  timestamptz,
  started_at   timestamptz,
  finished_at  timestamptz,
  error        text,
  primary key (job_name, slot_at)
);

Two separate processes then do two separate jobs:

  1. The ticker wakes up every minute (or whenever it is poked), looks at each job’s schedule, computes which slots should exist up to now, and inserts any missing ones. Because of the primary key, inserting the same slot twice is a no-op.
  2. Workers claim pending slots, run them, and record the outcome.

The important part: the ticker computes slots from the schedule and the current time, not from whether it was alive at the right moment. If the server was down from 02:58 to 03:40, the ticker wakes at 03:41, sees that the 03:00 slot is missing, and creates it. The run is late, not lost.

The slot is the identity

The slot time becomes the idempotency key for the whole run. The nightly scrape for slot 2026-03-14 03:00 UTC writes results tagged with that slot. If a worker crashes halfway and another retries, it overwrites the same slot’s output instead of creating a second batch. If you have already made your pipeline idempotent, the slot is the natural key to hang it on.

Claiming without double runs

Workers claim with a lease, using row locking so two workers never grab the same slot:

update scheduled_runs
set status = 'running', attempts = attempts + 1,
    lease_until = now() + interval '10 minutes', started_at = now()
where (job_name, slot_at) in (
  select job_name, slot_at from scheduled_runs
  where status = 'pending'
     or (status = 'running' and lease_until < now())
  order by slot_at
  limit 1
  for update skip locked
)
returning job_name, slot_at;

The worker extends lease_until with a heartbeat while it works. If the worker dies, the lease expires and the slot becomes claimable again. No orphaned ‘running’ rows forever.

Decide the catch-up policy per job

Once you can detect missed slots, you have to decide what to do with them. There is no universal answer, so I make it an explicit field on every job definition:

  • run_all - every missed slot runs, oldest first. I use it for billing reconciliation, daily exports to accounting, anything where a gap is a hole in the data.
  • latest_only - if several slots were missed, run only the newest and mark the rest as skipped. Perfect for price parsers and status checks. Nobody needs three stale snapshots from hours that already passed.
  • skip - missed is missed. Rare, but fine for things like a ‘post a motivational message to the team chat at 09:00’ bot.

The default matters. I default to latest_only, because run_all on a job that was down for a week can unleash 168 hourly scrapes at once and burn through your proxies and LLM budget in twenty minutes.

Decide the overlap policy too

The second explicit field: what happens if a slot comes due while the previous one is still running?

  • forbid - the new slot waits until the old one finishes. Safe default for scrapers sharing a session pool or a browser profile.
  • parallel - fine for stateless jobs, like enriching independent batches of leads.
  • replace - cancel the old run and start the new one. Only for jobs where freshness beats completeness, and only if your job actually supports cancellation.

With the slot table, forbid is a one-line check in the claim query: do not claim a slot for a job that already has a live lease.

Time zones and daylight saving

Businesses think in local time. ‘Send the digest at 08:00 Ho Chi Minh time’ or ‘run payroll export at 18:00 Berlin.’ Store the schedule in the business’s time zone, but compute and store slots in UTC.

That solves the fall-back problem automatically: when 02:30 local happens twice, both map to different UTC instants, so you need a rule. Mine is simple: when converting a local wall time to UTC, pick the first occurrence. When 02:30 local does not exist at all (spring forward), shift to the next valid minute. Write that rule down in the code with a comment, because the next developer will otherwise ‘fix’ it.

And please do not schedule business-critical jobs between 01:00 and 03:00 local time in zones that observe DST. Move them to 04:00 and the problem mostly disappears.

Add jitter before you hit rate limits

If every job is defined as ‘hourly at minute 0’, all of them start in the same second. For AI-heavy automations this is a self-inflicted rate limit. I add deterministic jitter: take a hash of the job name, map it to a number of seconds within a window (say 0 to 300), and add it to every slot. Deterministic matters, because the slot time must be stable for idempotency. Random jitter on each tick would create different slot keys.

Deadlines: late can be worse than never

This one is specific to automations whose output has a shelf life, which is most AI work. A morning summary generated after lunch is noise. An alert about a competitor price drop is useless after they changed it back.

Each job gets a max_lateness. When a worker claims a slot and finds that now() > slot_at + max_lateness, it marks the slot as expired instead of running it. That is a distinct status from failed or skipped, and it shows up in reports. Expired slots tell you your infrastructure is too slow for the promise you made, which is very different information from ‘the LLM returned garbage’.

I also attach a cost cap per slot for LLM jobs. If a retry loop on one slot crosses the cap, the slot fails hard. One bad slot should never eat the monthly budget.

Monitor for silence, not just errors

Error alerts cannot catch a run that never started. You need a dead man’s switch: an alert that fires when something good did not happen.

With the slot table this is a single query run by a separate process, ideally on separate infrastructure from the scheduler:

  • For each job, find the latest slot with status ‘done’.
  • If it is older than the job’s interval plus max_lateness, alert.
  • Also alert if any slot has been ‘pending’ longer than its max_lateness. That means the ticker works but workers are dead.

If the monitoring process itself might die, ping an external heartbeat service from it. Then the only way to get no alert is for everything to be healthy.

Use hosted cron as a doorbell, not a scheduler

You do not have to run your own always-on ticker. On serverless setups, I use the platform’s cron feature only to call an endpoint that runs the ticker logic. The ticker reads the schedules, computes missing slots from the database, and enqueues them.

This turns an unreliable scheduler into an acceptable one. If the platform rings the doorbell 40 minutes late, the ticker still sees exactly which slots are due. If it skips a ring entirely, the next ring catches up. The source of truth is your database and the clock, not the platform’s best effort.

The checklist I apply to every scheduled job

  1. Slots are rows with a unique key of job name plus UTC slot time.
  2. The ticker computes missing slots from the schedule, not from its own uptime.
  3. Workers claim with a lease and heartbeat, using skip-locked claiming.
  4. Every job declares catch-up policy, overlap policy, max_lateness and a cost cap.
  5. Schedules live in business local time, slots in UTC, with a written DST rule.
  6. Deterministic jitter spreads load away from the top of the hour.
  7. A separate monitor alerts on silence, not only on errors.

It is maybe 300 lines of code. It has saved me from more angry client messages than any model upgrade ever has.

FAQ

Do I need a dedicated workflow engine like Temporal for this?

Not for most MVPs and automation projects. A Postgres table, a ticker and a worker loop cover scheduled parsers, digests and bots very well. I reach for a full workflow engine only when jobs have many long-running steps with complex compensation logic. Start with the slot table and migrate later if you outgrow it.

What catch-up policy should I pick for a web scraper?

Usually latest_only. If a price or stock scraper misses three hourly runs, running all three later gives you three stale snapshots and triples proxy and captcha costs. Run the newest slot, mark the others as skipped, and only use run_all when the gap itself is a data problem, like daily accounting exports.

How do I monitor a job that silently never runs?

Use a dead man's switch. A separate monitoring process checks, for each job, when the last successful slot finished. If that time is older than the interval plus the allowed lateness, it alerts. Run the monitor on different infrastructure from the scheduler and have it ping an external heartbeat service so its own death is also detected.

Related articles