A scheduled task missed its time: catch up, skip, or stop

Three different decisions for missed schedule occurrences: bounded digest catch-up, skipping obsolete cleanup, and stopping a sensitive intent until reconciliation.

Three paths after a pause: cover what was missed, choose what is current, or wait for a decision.

The service has returned after downtime, the timer is active again, and the worker accepts work. Yet nobody has prepared the digest for the missed interval. Another task has already started an old cleanup, although only the latest intent remained relevant. Both situations can occur with working automatic startup: restoring a process and restoring the meaning of its work require different decisions.

What should happen to schedule occurrences that passed without a handler? The answer depends on what each run means. The independent planner in one Symfony Demo uses MySQL 8.4, InnoDB tables, and native PDO MySQL. Checks cover missed-occurrence selection, persisted decisions, and rollback of local effects. The example sends no emails, deletes no real data and makes no payments.

Separate three events first

In conversation, the scheduled instant is often mixed up with the actual start time. scheduled_due is when work should have become due under the agreed schedule. resume_time is when the handler returns. executed_at is the time of a particular run's local effect. The first value determines membership in the schedule; the other two describe what happened later.

A missed occurrence also differs from a failed attempt at already accepted work. First decide whether to create domain work for this occurrence at all. Only after acceptance do retry budgets and continuation become relevant. If an external result is already unknown, another timer wake-up does not authorize declaring the action unperformed and starting it again.

Symfony's Scheduler documents stateful() for retaining schedule state and processOnlyLastMissedRun(true) for processing only the last missed run. Consider these capabilities before writing infrastructure. They help determine message generation, but do not themselves establish which business effect has completed or which omission may be discarded.

Freeze a small time model

UTC and a ten-minute interval are enough for the first check. Counting begins at minute 0, which is not a task. The first due occurrences are 10, 20, and 30. Imaginary downtime covers these three occurrences, and processing resumes at minute 35. Eligibility is precise: epoch < scheduled_due <= now. A call exactly at minute 30 therefore already sees the third occurrence; a call at minute 9 sees none.

This is a fixed interval, rather than a calendar rule such as “every day at a particular local hour.” Daylight-saving transitions, time-zone changes, and schedule edits require a separate agreement. A conclusion about ten minutes in UTC should not silently become a conclusion about an ambiguous autumn hour.

Each occurrence has a stable key: the synthetic job name, policy version, and due Unix instant. The explanation abbreviates it to digest@10, although the ledger stores the full identity. The actual start minute is excluded from the key: another wake-up at minute 35 must recognize the same work rather than create new work.

Digest: catch up while preserving boundaries

Suppose each digest describes its own ten-minute interval: (0,10], (10,20], and (20,30]. The example's product decision requires preserving all these parts. One late digest describing “the state now” cannot replace three historical slices if those slices are what the reader expects.

Recovery must nevertheless avoid releasing an unlimited stream of work. The policy permits at most two oldest unfinished occurrences per call. At minute 35, expect digest@10 and digest@20 to be selected; digest@30 remains pending. A second call at the same instant may complete the third occurrence. This is useful backlog continuation rather than duplication of a completed effect.

A third call at minute 35 should create no effects. “Two per call” is not a global rate limit: call frequency is a separate decision. Real delivery would also need an acceptable message age, quotas, recipient volume, and a policy for stale content. Here the checks concern only occurrence selection and local completion.

Cleanup: skip an obsolete intent

For the second task, agree on different semantics: each cleanup means “bring the synthetic state up to the current boundary.” A newer intent completely covers previous ones, and skipping an intermediate run loses no separate mandatory action. That property is what permits coalescing the work.

At minute 35, the planner should mark cleanup@10 and cleanup@20 as skipped, with reason obsolete_latest_intent, and select only cleanup@30. Skipping is not disguised as completed: the older runs did not happen. A repeat call preserves those decisions and creates no new local effect for minute 30.

The name cleanup guarantees nothing by itself. If every run must create a separate archive, perform a legally significant retention step, or transfer unique data, a newer intent may not cover an older one. Coalescing would then be the wrong policy. Before choosing it, establish exactly what could be lost between two boundaries.

Billing-like: stop automatic replay

The third task resembles a financial operation only in requiring a cautious decision. It records synthetic intents; it has no payment provider, invoices, or charges. For each of minutes 10, 20, and 30, the chosen rule returns blocked, with reason explicit_reconciliation_required. The expected number of automatic effects is zero.

This does not assert that all billing must always be handled manually. It refuses to invent a universal replay rule without a domain operation contract. The product owner must define the accrual period, intent identity, authoritative result source, and permitted reconciliation procedure. A separate verified automatic process may follow that decision.

Until then, every unresolved occurrence remains visible. It cannot be hidden behind a green worker status or a later successful run of another task. Stopping automatic replay is a concrete state with a reason and a next responsible party, rather than silently forgetting outstanding work.

Job Selection at minute 35 What remains after a successful local commit
digest 10, 20 30 is pending; 10 and 20 are completed
cleanup 30 10 and 20 are skipped; 30 is completed
billing_like nothing 10, 20, 30 are blocked; completed is empty

The ledger must show decisions, not just the last success

A single last_run too easily conceals the difference between observed, selected, and completed work. The teaching ledger stores the due instant, state, reason, and separate execution time. The planner's response distinguishes selected, skipped, blocked, pending, and completed. Selection is not completion: before commit it is only the current call's intent.

Here last_completed means the maximum due instant among locally completed rows. It is an observation, rather than a discovery cursor. For cleanup it may equal 30 even though 10 and 20 were skipped; for billing-like it remains empty. Enumeration of due occurrences uses the agreed origin and stored rows, so a large watermark does not erase unfinished or skipped records.

Before running the planner, a separate migrator prepares the InnoDB schema; tests use App\Infrastructure\MysqlLab within the guarded disposable MySQL fixture. Complete initialization before the business transaction: MySQL DDL can cause an implicit commit. This is neither an atomic schema upgrade nor an automatic data transfer from the old SQLite store. At runtime the planner performs DML only, without CREATE, ALTER, or DROP. The first stage separately records all discovered occurrences as pending. The second stage writes local effects and decisions in one transaction. The effect's unique key is tied to the immutable occurrence identity. That commit covers only data in MySQL; sending an email or making an external payment is outside it.

If the second stage is deliberately failed before commit, expect effects, completions, and skip decisions to roll back. Previously discovered rows remain pending; last_completed does not advance. The next call may select them again. This checks a controlled exception, rather than proving recovery after SIGKILL or an unknown remote commit result.

Check the policy before connecting a timer

MockClock fixes and advances time without wall-time waiting. The planner uses the existing Clock/PDO dependencies in one Symfony 8.1 Demo, with an effective PHP minimum of 8.4.1. The kernel test confirmed Planner wiring; policy tests used MockClock. No Scheduler transport, cron, daemon or systemd ran.

Actual rows confirmed the frozen expectations: at resume35, digest completed 10/20 and left pending 30; the second tick at the same 35 completed 30, the third did nothing, effects=3. Cleanup completed 30 and marked 10/20 skipped, effects=1; billing_like blocked 10/20/30 without completed rows or effects. Exact30 included due30, before9 produced no work, and long95 retained pending 30..90 after cap=2. Two precommit failures preserved discovery pending10/20/30 while rolling back effects/completion/skips; reopening did not duplicate an effect.

Ledger state is checked with direct SQL through a separate native PDO connection sharing the same MySQL schema after ticks, rollback, and reconnection: occurrence and effect rows, scheduled due, and executed_at. An independent MAX(due) over completed rows alone must match last_completed; reconnecting must not create a duplicate effect. This checks the metric's narrow meaning rather than making it a coverage cursor. A separate read connection does not establish correctness for concurrent handlers. The model is limited to local data: it does not prove a real queue, billing, scheduler daemon, DST, or crash recovery.

The cap itself does not bound the cost of searching all past time. Teaching enumeration therefore has a separate limit of 10,000 occurrences and refuses before changes when that limit is exceeded. This is a guardrail for a small lab. Long-term operation needs discovery pages, a durable cursor with explicit semantics, and separate retention of every unresolved occurrence; moving a cursor for speed must not lose outstanding work.

A missed-schedule decision begins with the meaning of a unit of work. A historical interval may require bounded catch-up, a replaceable current intent may permit explicit skip, and an uncertain sensitive action may require stopping until reconciliation. Only then should the triggering mechanism and its recovery be chosen and tested. An active timer confirms readiness to wake a handler; the domain ledger must explain the fate of every missed occurrence.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against an owned disposable MySQL schema:

bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/MissedSchedule
  1. Symfony Core Scheduled publication: time, time zones and repeated execution
  2. Platform Engineering Who should retry a failed operation: one retry owner
  3. Platform Engineering Timeout after an external request: when the outcome is unknown