Job options
The last argument of every(), cron() and at() is an options object (in .NET, EveryJobOptions, CronJobOptions or JobOptions, usually written new() { ... }). Every option has a default, so you only set what you need.
Summary
Section titled “Summary”| Node.js | .NET | Default | Needs a lease backend | What it controls |
|---|---|---|---|---|
jitterMs |
Jitter |
scheduler’s (2 s), lowered for short intervals | no | The random delay before claiming |
maxLateMs |
MaxLate |
scheduler’s (60 s) | no | How late an instance may start a run |
timeoutMs |
Timeout |
none | no | The longest a run may take |
overlap |
Overlap |
skip | yes | Whether a run may start while the previous one is going |
maxAttempts |
MaxAttempts |
3 |
yes | How many times a run may be started when runners die |
catchUpMs |
CatchUp |
5 min | yes | How old a missed run may be and still run on start |
yieldAfterFailure |
YieldAfterFailure |
false | yes | Whether an instance that just failed the job lets a healthy one claim the next run first |
historySize |
HistorySize |
scheduler’s (1000) | no | How many runs to remember |
historyTtlMs |
HistoryTtl |
scheduler’s (none) | no, but not RabbitMQ or NATS | How long to remember them |
offsetMs |
Offset |
0 |
no | Interval jobs only: shifts the grid |
timezone |
TimeZone |
scheduler’s | no | Cron jobs only: the time zone |
data |
Data |
none | no | Data for the job’s runs, read in the handler as ctx.data (ctx.Data) |
Durations are milliseconds in Node.js and TimeSpan values in .NET. “Scheduler’s” means the option of the same name on the scheduler. See Scheduler options.
An option that needs a lease backend isn’t offered on another one: RabbitMQ, or NATS, Redis or Valkey without their lease strategy, don’t take the overlap, the attempts, the catch-up or yield-after-failure. A one-off job never takes the overlap, since it has no previous run.
In TypeScript, every(), cron() and at() don’t accept those options on such a backend: the code doesn’t compile. Decorators and plain JavaScript can’t be checked that way, so the job is refused when it is added, with an error that names the option and the backend.
The job is refused when it is added, with an AnarchonException of code Unsupported that names the option and the backend.
jitterMs
Section titled “jitterMs”Each instance waits a random time between 0 and the jitter (jitterMs, Jitter) after the slot before it claims the run. With yieldAfterFailure, an instance whose last run of the job failed waits longer.
flowchart LR slot["slot<br/>12:00:00.000"] --> window["each instance picks a random moment<br/>in the next jitterMs"] --> claim["first one to ask wins"]
- Larger jitter spreads work more evenly and makes the start time less exact.
0means no spreading: all instances claim at the same instant, and the one with the fastest clock and connection usually wins.
It must be under half the time between runs. If you don’t set it, the default is the scheduler’s jitter (2 seconds), or a quarter of the interval when that is smaller. So a job that runs every second gets 250 ms.
Works on every backend. Use it when:
- A heavy job should land on a random instance: a larger jitter spreads the runs, so one instance doesn’t do every nightly rebuild.
- The start time matters to the second: no jitter (
jitterMs: 0,Jitter = TimeSpan.Zero). The fastest instance then wins every time; that is the price. - Many instances call one dependency at the same moment: jitter spreads the first requests over a few seconds.
maxLateMs
Section titled “maxLateMs”When an instance gets to a run more than the lateness limit (maxLateMs, MaxLate) after its slot, it skips it and emits a skip event with reason late (skip and 'late' in Node.js, Skipped and SkipReason.Late in .NET).
This protects you from stale runs. A process can be frozen for minutes: a suspended laptop, a long garbage-collection pause, a stalled virtual machine. When it wakes, its timers fire for runs that were due long ago. Without this limit it would start them.
It must be bigger than the jitter.
Works on every backend. On RabbitMQ, and NATS, Redis or Valkey without their lease strategy, the jitter plus the lateness limit must also be shorter than how long the backend remembers a claimed run, or a late instance could win the same run again; anarchon checks it when the job is added. Use it when:
- A stale run is worse than none: quotes, presence, anything whose inputs age in seconds. Keep it short.
- A late run is still useful: a cleanup or a report can run half an hour late. Raise it.
timeoutMs
Section titled “timeoutMs”After this long, the run’s cancellation fires (ctx.signal aborts, ctx.CancellationToken is cancelled) and the run is recorded as failed, with the error TimeoutError: Timed out after N ms (TimeoutException: Timed out after N ms in .NET).
Set a timeout on any job that can hang. With the default overlap (skip), a hung run keeps renewing its lease and blocks every later run of that job.
Works on every backend. Use it when:
- The job calls anything over the network: a hung connection must not hold the job forever. Pass
ctx.signal(ctx.CancellationToken) along. - The job must end before its next run is due: set it below the interval, so a slow run fails and the next one starts on time.
overlap
Section titled “overlap”Needs a lease backend.
What happens when a run is due while the previous run of the same job is still going:
- Skip (default;
'skip',OverlapPolicy.Skip): the new run is skipped, with a skip event of reason overlap. - Allow (
'allow',OverlapPolicy.Allow): both run.
Skipped runs are not queued. The run at :03 never happens; the next run to start is the first one due after the current run ends.
Works on lease backends: PostgreSQL, SQL Server (.NET), SQLite, Redis, Valkey or NATS with their lease strategy. On the others, runs can always overlap; if two must not, guard inside the job (a database lock, for example). Use it when:
- Skip: runs of the job write the same data: a sync, an export, a reindex. Two at once would fight.
- Allow: each run stands alone: a ping, a metrics sample, a check whose result is only logged.
maxAttempts
Section titled “maxAttempts”Needs a lease backend.
How many times one run may be started when its runner dies, counting the first try. The default is 3.
- A run is retried only when its runner stopped renewing the lease: it crashed, froze or lost the network.
- A run that fails (the handler throws) is not retried. Retries are for dead runners, not for errors. If you want to retry errors, do it inside the handler.
- A hand-over on stop doesn’t count against the limit.
When the limit is used up, the run is marked interrupted and left.
Works on lease backends. Use it when:
1: the side effect must never happen twice and isn’t idempotent: payments, messages without a deduplication key. A run that stopped halfway needs a person, not a retry.3(the default): the job is safe to redo, or resumes from a checkpoint.- More: a long, idempotent job on infrastructure where instances come and go.
catchUpMs
Section titled “catchUpMs”Needs a lease backend.
On start, an instance checks the latest slot of each job. If nobody ran it and it was due less than the catch-up window ago, the instance runs it now, with the reason catch-up (ctx.reason === 'catch-up', ctx.Reason == RunReason.CatchUp).
This covers a run that was due while every instance was down, for example during a full restart.
Only the latest run is caught up, not every run that was missed.
Works on lease backends. Use it when:
- A daily or monthly business job must happen even after a long outage: hours, or a day.
- An hourly job: up to about the interval, so a caught-up run doesn’t land right before the next one.
- A frequent job: zero, since the next run is moments away.
yieldAfterFailure
Section titled “yieldAfterFailure”Needs a lease backend.
Each run goes to the instance that claims it first, healthy or not. A fault that stays with one instance (a broken connection pool, a full disk, a dependency only that instance can’t reach) fails every run that instance wins, while a healthy instance could have run them. A run that throws isn’t retried.
With yield-after-failure on (yieldAfterFailure: true, YieldAfterFailure = true), an instance whose last run of the job failed (it threw or timed out) waits before claiming the job’s next scheduled run:
- Healthy instances first. They claim by slot + jitter. The instance that failed waits until slot + jitter + heartbeat, so one of them wins.
- It still runs when no one else does. If no other instance has claimed the run by then, the instance that failed claims and runs it. A single instance keeps running its jobs.
- It recovers by itself. A run that succeeds on that instance ends the waiting.
- Never refused as late. The wait never ends past the lateness limit after the slot.
What it costs. When only failing instances are left, a run starts up to one heartbeat later than usual: between slot + jitter and slot + jitter + heartbeat. With the default timings (jitter 2 s, heartbeat 5 s), that is up to 7 s after the slot instead of 2 s. Manual runs, takeovers and catch-up never wait.
What it doesn’t do. The run that failed isn’t retried, and a handler that hung keeps running on its instance (see the timeout). Every instance remembers only its own last run, so after a failure on every instance, all of them wait the same and the race goes on as before, one heartbeat later.
Works on lease backends. Use it when:
- Instances can be sick on their own: jobs that use a connection or resource per instance.
- A job is frequent enough that a few seconds’ delay doesn’t matter. Leave it off where the start time matters more than the instance.
historySize and historyTtlMs
Section titled “historySize and historyTtlMs”The history size (historySize, HistorySize) is about how many runs to keep per job, and the history age limit (historyTtlMs, HistoryTtl) also drops records older than a given age.
RabbitMQ and NATS trim history by count only, so they refuse an age limit. NATS keeps one history size for all its jobs: the largest of the backend’s and every job’s.
On lease backends a small historySize is always safe: a run is never forgotten while a late claim could still ask for it. On claim-only backends the store’s memory of claimed runs also has to cover late instances; anarchon checks this when you add the job and throws if the settings are unsafe. See Timing and clocks.
Works on every backend; the age limit not on RabbitMQ or NATS. Use it when:
- A frequent job: keep a few hundred runs at most; nobody reads more.
- Audits or compliance: keep a year by age, with a count large enough to hold it.
Values by kind of job
Section titled “Values by kind of job”A starting point for common jobs. “default” means leave it unset.
| Kind of job | Jitter | Lateness limit | Timeout | Overlap | Attempts | Catch-up | Runnable example |
|---|---|---|---|---|---|---|---|
| Payments, billing | default | default | yes | default | 1 |
hours | billing.ts, Billing |
| Daily report or digest | minutes | 30 min | yes | default | default | hours | |
| Export or ETL longer than its interval | default | default | under the interval | default | default | up to the interval | nightly-export.ts, NightlyExport |
| Cache refresh every few seconds | about a third of the interval | short | short | default | default | zero | cache-refresh.ts, CacheRefresh |
| Metrics sample, ping | zero | short | short | allow | 1 |
zero | |
| Sending what an outbox holds | default | under the backend’s memory | yes | broker-notifications.ts, BrokerNotifications |
|||
One-off migration (at(), At()) |
zero | long | long | 1 |
long |
An empty cell means the job doesn’t need the option. The outbox job needs no lease option at all, so it runs on any backend, RabbitMQ and NATS included; the overlap doesn’t apply to one-off jobs.