summaryrefslogtreecommitdiff
path: root/cli/tsc
diff options
context:
space:
mode:
authorIgor Zinkovsky <igor@deno.com>2023-11-01 11:57:55 -0700
committerGitHub <noreply@github.com>2023-11-01 11:57:55 -0700
commit01d3e0f317ca180bbf0ac8a17c6651869110e02f (patch)
treeb8e3bb91e87cf396bfa782f6377158f8a170b32b /cli/tsc
parent82643857cc77a80f9a819584035ec147a6114553 (diff)
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`.
Diffstat (limited to 'cli/tsc')
-rw-r--r--cli/tsc/dts/lib.deno.unstable.d.ts25
1 files changed, 25 insertions, 0 deletions
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
@@ -1319,6 +1319,31 @@ declare namespace Deno {
/** **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> | void,
+ options?: { backoffSchedule?: number[]; signal?: AbortSignal },
+ ): Promise<void>;
+
+ /** **UNSTABLE**: New API, yet to be vetted.
+ *
* A key to be persisted in a {@linkcode Deno.Kv}. A key is a sequence
* of {@linkcode Deno.KvKeyPart}s.
*