Skip to main content

cron

function Deno.cron
unstable
Jump to headingcron(
name: string,
schedule: string | CronSchedule,
handler: () => Promise<void> | void,
): Promise<void>

Create a cron job that will periodically execute the provided handler callback based on the specified schedule.

Deno.cron("sample cron", "20 * * * *", () => {
  console.log("cron job executed");
});
Deno.cron("sample cron", { hour: { every: 6 } }, () => {
  console.log("cron job executed");
});

schedule can be a string in the Unix cron format or in JSON format as specified by interface CronSchedule, where time is specified using UTC time zone.

Parameters Jump to heading

Jump to headingname: string
Jump to headingschedule: string | CronSchedule
Jump to headinghandler: () => Promise<void> | void

Return Type Jump to heading

Promise<void>
Jump to headingcron(
name: string,
schedule: string | CronSchedule,
options: { backoffSchedule?: number[]; signal?: AbortSignal; },
handler: () => Promise<void> | void,
): Promise<void>

Create a cron job that will periodically execute the provided handler callback based on the specified schedule.

Deno.cron("sample cron", "20 * * * *", {
  backoffSchedule: [10, 20]
}, () => {
  console.log("cron job executed");
});

schedule can be a string in the Unix cron format or in JSON format as specified by interface CronSchedule, where time is specified using UTC time zone.

backoffSchedule option can be used to specify the retry policy for failed executions. Each element in the array represents the number of milliseconds to wait before retrying the execution. For example, [1000, 5000, 10000] means that a failed execution will be retried at most 3 times, with 1 second, 5 seconds, and 10 seconds delay between each retry. There is a limit of 5 retries and a maximum interval of 1 hour (3600000 milliseconds).

Parameters Jump to heading

Jump to headingname: string
Jump to headingschedule: string | CronSchedule
Jump to headingoptions: { backoffSchedule?: number[]; signal?: AbortSignal; }
Jump to headinghandler: () => Promise<void> | void

Return Type Jump to heading

Promise<void>
Back to top