Guides
Overlapping runs
By default a job never overlaps itself. If a run is still going when the next tick comes due, that tick is skipped and counted.
* * * * * * with a callback that takes 2.3 seconds.With protection on
overrunProtection is on by default, which is what you want for most jobs. A slow run can’t pile up on top of itself, and a stuck database won’t collect a queue of queries.
A skipped tick is gone. It isn’t queued to run later, so the job picks up again at the first tick after the current run finishes. The number of skips is in the job’s metrics, and it’s worth watching. A steadily rising count means the job takes longer than its schedule allows.
const { skippedExecutions = 0 } = baker.getMetrics("sync-orders");
if (skippedExecutions > 0) {
console.warn(`sync-orders has skipped ${skippedExecutions} runs`);
}skippedExecutions isn’t set until the first skip, so give it a default as above.
With protection off
Set overrunProtection: false to start a new run on every tick, whatever the previous run is doing.
baker.add({
name: "ping-services",
cron: "*/10 * * * * *",
overrunProtection: false,
callback: pingServices,
});This suits work where each tick is independent, such as polling a set of endpoints with its own timeouts. There is no limit on concurrency, so if runs take longer than the gap between ticks they’ll keep accumulating until they finish or your process runs out of something.
What counts as finished
A run holds its place until its callback has settled and onTick or onError has finished, because both are awaited. A slow error handler can therefore cause skips as well.
Protection applies to one job at a time. Two different jobs can always run at once, even if they share a callback. If they mustn’t overlap, you’ll need your own lock around the work.