From 01d3e0f317ca180bbf0ac8a17c6651869110e02f Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Wed, 1 Nov 2023 11:57:55 -0700 Subject: feat(cron) implement Deno.cron() (#21019) This PR adds unstable `Deno.cron` API to trigger execution of cron jobs. * State: All cron state is in memory. Cron jobs are scheduled according to the cron schedule expression and the current time. No state is persisted to disk. * Time zone: Cron expressions specify time in UTC. * Overlapping executions: not permitted. If the next scheduled execution time occurs while the same cron job is still executing, the scheduled execution is skipped. * Retries: failed jobs are automatically retried until they succeed or until retry threshold is reached. Retry policy can be optionally specified using `options.backoffSchedule`. --- cli/tsc/dts/lib.deno.unstable.d.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli/tsc/dts/lib.deno.unstable.d.ts') diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 56188f3b8..c758e620c 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1317,6 +1317,31 @@ declare namespace Deno { */ export function openKv(path?: string): Promise; + /** **UNSTABLE**: New API, yet to be vetted. + * + * Create a cron job that will periodically execute the provided handler + * callback based on the specified schedule. + * + * ```ts + * Deno.cron("sample cron", "*\/20 * * * *", () => { + * console.log("cron job executed"); + * }); + * ``` + * `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. + * + * @category Cron + */ + export function cron( + name: string, + schedule: string, + handler: () => Promise | void, + options?: { backoffSchedule?: number[]; signal?: AbortSignal }, + ): Promise; + /** **UNSTABLE**: New API, yet to be vetted. * * A key to be persisted in a {@linkcode Deno.Kv}. A key is a sequence -- cgit v1.2.3