# How to stop cron jobs from overlapping without Redis

Gregale · Updated 2026-12-05

Skip a scheduled run when the previous one is still active, then verify the skipped tick and the next successful run in Gregale.

Your five-minute job took seven minutes. Should the next run start anyway? On Gregale, choose `overlap: "skip"` to let the active run finish and skip the next scheduled occurrence. Then check occurrence history: a skipped tick should be recorded as `skipped_overlap`, not silently disappear.

| Policy    | What it does                                                                                                                   |
| --------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `skip`    | Leaves the active run alone and skips this tick. Use it when the next run can catch up.                                        |
| `allow`   | Lets independent runs overlap.                                                                                                 |
| `replace` | A newer command run can stop the old one. For an already dispatched HTTP cron, Gregale waits for the previous request instead. |

Stopping a command does not undo its side effects. See the [Crons API](https://gregale.dev/docs/api/crons) for the difference between command and HTTP replacement.

If work must survive a skipped tick, use an independent producer that records it durably, or let the next run catch up from a persisted cursor. Enqueueing only inside the skipped cron cannot save work the cron never enqueued. Give each unit of work a stable ID so catch-up and retries can safely see it twice. The policy applies to scheduled occurrences of **one cron**, not separate crons, worker replicas, manual triggers, or other apps.

## Make Gregale skip an overlapping scheduled run

This example uses a [command cron](https://gregale.dev/docs/crons.md#command-crons-preview) because the run needs to exceed the one-minute demo interval. Command crons are in preview and need app tasks. Check `gregale feature list` and use an isolated test workspace. A short HTTP cron is a different test: don't assume it can stay open across a minute.

[Download and extract the starter](https://gregale.dev/examples/prevent-overlapping-cron-jobs.zip). Use Bash, curl, jq, OpenSSL, Python 3 and the Gregale CLI. With a test-workspace credential in `FAAS_TOKEN`, create a fresh internal app and deploy its tiny container. The helper refuses to reuse an existing app.

```bash
set -euo pipefail
export GREGALE_TOKEN="$FAAS_TOKEN"
export GREGALE_API_URL=https://api.gregale.dev FAAS_API=https://api.gregale.dev
APP="demo-cron-overlap-$(openssl rand -hex 8)"
umask 077
RECEIPTS="$(mktemp -d "${TMPDIR:-/tmp}/cron-overlap.XXXXXX")"
printf 'Recovery files: %s\n' "$RECEIPTS"
printf '%s\n' "$APP" > "$RECEIPTS/app-name"
APP_ID="$(bash create-app.sh "$APP")"
printf '%s\n' "$APP_ID" > "$RECEIPTS/app-id"
g() { gregale --non-interactive --json "$@"; }
DEPLOYMENT="$(g deploy --name "$APP" --source=worktree --no-wait --yes |
  jq -er --arg app "$APP_ID" 'select(.app_id == $app) | .id')"
g release wait "$DEPLOYMENT" --app "$APP" --timeout 5m |
  jq -e --arg id "$DEPLOYMENT" '.id == $id and .status == "live"'
g app get "$APP" |
  jq -e --arg app "$APP_ID" '.id == $app and .visibility == "internal"'
```

Once the deployment is live, generate the schedule just before creating the cron. The planner picks three consecutive UTC minutes on one calendar date. If those minutes would cross the hour, it starts at the next hour. The task timeout limits each command, not the schedule's lifetime.

```bash
python3 plan-window.py > "$RECEIPTS/window.json"
jq '.ticks' "$RECEIPTS/window.json"
SCHEDULE="$(jq -er .schedule "$RECEIPTS/window.json")"
COMMAND="$(jq -er .command "$RECEIPTS/window.json")"
g cron create --app "$APP" --schedule "$SCHEDULE" --timezone UTC --shell \
  --command "$COMMAND" --timeout-seconds 110 \
  --schedule-policy '{"version":1,"overlap":"skip","missed_runs":"coalesce_latest"}' \
  > "$RECEIPTS/cron.json"
CRON_ID="$(jq -er --arg app "$APP_ID" --arg schedule "$SCHEDULE" --arg command "$COMMAND" '
  select(.app_id == $app and .kind == "command" and .schedule == $schedule
    and .timezone == "UTC" and .command == [$command]
    and .schedule_policy.version == 1 and .schedule_policy.overlap == "skip")
  | .id | strings | select(length > 0)
' "$RECEIPTS/cron.json")"
```

This is a narrow firing window, not automatic expiry. The five-field expression can match the same date in a later year. The command checks the original UTC window and exits without its 75-second workload if started outside it, but a later tick could still start a no-op task. Always disable and delete the test cron. The missed-run policy is separate: it considers the latest eligible missed tick rather than replaying all missed ticks.

Use nominal schedule times, not the time you happened to poll. Do not use `cron run` for this test: that starts a manual run instead of observing what the schedule decided.

```bash
g cron occurrences "$CRON_ID" --limit 20 > "$RECEIPTS/occurrences.json"
if ! python3 verify-occurrences.py "$RECEIPTS/occurrences.json"; then
  printf '%s\n' 'No complete proof yet. Check the same cron again.'
fi
```

The checker looks for three consecutive one-minute ticks: a successful run that was still active at the next tick, a skipped tick naming that run as its blocker with no task of its own, and a successful later run with a different task ID. Wait for the third tick to finish and re-read the same cron if you checked too early. A missed deadline or a coalesced tick is not proof of overlap protection.

If interrupted, open a fresh shell with the same test credential, restore the `g` helper, and recover `APP` and `APP_ID` from the printed recovery directory. Read `CRON_ID` from the saved create response. If the cron response was lost, do not create another cron. List with `gregale cron list --app "$APP" --json`, and recover the ID only if exactly one command cron matches the saved app ID, UTC schedule, and command in `window.json`. If the app creation response was lost or the resources cannot be identified unambiguously, inspect the disposable workspace before deleting anything.

Before cleanup, verify the cron still belongs to the disposable app. Disable and delete that exact cron when done, then remove only the app you created. Disabling a cron stops future ticks, not a command already running. Wait for any active test command to finish before removing the app.

```bash
g cron get "$CRON_ID" |
  jq -e --arg cron "$CRON_ID" --arg app "$APP_ID" '.id == $cron and .app_id == $app'
g cron update "$CRON_ID" --disable |
  jq -e --arg cron "$CRON_ID" --arg app "$APP_ID" '
    .id == $cron and .app_id == $app and .enabled == false
  '
# Wait until there are no pending, queued or running occurrences.
g cron occurrences "$CRON_ID" --limit 20
```

Then run `gregale cron delete "$CRON_ID" --yes`. Recheck that `gregale app get "$APP"` still returns your exact internal app with `APP_ID` before running `gregale app delete "$APP" --yes`.

## What we verified on Gregale

We deployed the revised starter ZIP to a disposable internal app and scheduled three ticks: 15:25, 15:26 and 15:27 UTC. The first command was still running at 15:26 and finished successfully. The middle tick recorded `skipped_overlap`, named the first occurrence as its blocker, and had no task of its own. The 15:27 tick started a different task that also finished successfully. The downloadable checker passed against the hosted occurrence records.

This was a test of one command cron's `skip` policy. We did not test `allow`, `replace`, manual runs, or scheduler downtime.

## What this does not guarantee

A retry, manual trigger or second scheduler can still reach your app. Make writes idempotent using the identity of the work, such as the import window or source record ID. Overlap, missed runs and start deadlines are separate choices in the [scheduling policy](https://gregale.dev/docs/crons.md#advanced-scheduling). Use [cron run diagnostics](https://gregale.dev/articles/why-cron-job-did-not-run) when you need to tell a skip from a delivery failure.

## Questions

### How do I stop scheduled cron jobs from overlapping?

Set the schedule policy for the Gregale cron to overlap: skip. If an earlier scheduled run is still active, Gregale skips the new tick and records skipped_overlap in occurrence history.

### Does skipping an overlapping cron run stop the current run?

No. Skip leaves the current run alone. It drops the overlapping scheduled tick and does not replay that tick later.

### Do I still need idempotency if cron overlap is disabled?

Yes. The policy applies to scheduled occurrences of one cron, not all paths that can trigger the work. Retries, manual runs or another scheduler can still cause repeated work.

Canonical URL: https://gregale.dev/articles/prevent-overlapping-cron-jobs

