summaryrefslogtreecommitdiff
path: root/cli/tsc
diff options
context:
space:
mode:
authorIgor Zinkovsky <igor@deno.com>2023-11-16 14:19:00 -0800
committerGitHub <noreply@github.com>2023-11-16 14:19:00 -0800
commitb572abfcb3fadbfdd3ce671a27463d67bcb77534 (patch)
treea3b783218079b01b16a331f7522d3a3935603520 /cli/tsc
parent6b42cecc064d01d87aae978ecd7eb372bfe9a34e (diff)
feat(ext/cron) modify Deno.cron API to make handler arg last (#21225)
This PR changes the `Deno.cron` API: * Marks the existing function as deprecated * Introduces 2 new overloads, where the handler arg is always last: ```ts Deno.cron( name: string, schedule: string, handler: () => Promise<void> | void, ) Deno.cron( name: string, schedule: string, options?: { backoffSchedule?: number[]; signal?: AbortSignal }, handler: () => Promise<void> | void, ) ``` This PR also fixes a bug, when other crons continue execution after one of the crons was closed using `signal`.
Diffstat (limited to 'cli/tsc')
-rw-r--r--cli/tsc/dts/lib.deno.unstable.d.ts57
1 files changed, 56 insertions, 1 deletions
diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts
index 3ca8a212a..5cba27a5e 100644
--- a/cli/tsc/dts/lib.deno.unstable.d.ts
+++ b/cli/tsc/dts/lib.deno.unstable.d.ts
@@ -1334,12 +1334,67 @@ declare namespace Deno {
* second, 5 seconds, and 10 seconds delay between each retry.
*
* @category Cron
+ * @deprecated Use other {@linkcode cron} overloads instead. This overload
+ * will be removed in the future.
*/
export function cron(
name: string,
schedule: string,
handler: () => Promise<void> | void,
- options?: { backoffSchedule?: number[]; signal?: AbortSignal },
+ options: { backoffSchedule?: number[]; signal?: AbortSignal },
+ ): Promise<void>;
+
+ /** **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");
+ * });
+ * ```
+ *
+ * `schedule` is a Unix cron format expression, where time is specified
+ * using UTC time zone.
+ *
+ * @category Cron
+ */
+ export function cron(
+ name: string,
+ schedule: string,
+ handler: () => Promise<void> | void,
+ ): Promise<void>;
+
+ /** **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 * * * *", {
+ * backoffSchedule: [10, 20]
+ * }, () => {
+ * console.log("cron job executed");
+ * });
+ * ```
+ *
+ * `schedule` is a Unix cron format expression, 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.
+ *
+ * @category Cron
+ */
+ export function cron(
+ name: string,
+ schedule: string,
+ options: { backoffSchedule?: number[]; signal?: AbortSignal },
+ handler: () => Promise<void> | void,
): Promise<void>;
/** **UNSTABLE**: New API, yet to be vetted.