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`. --- ext/cron/interface.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ext/cron/interface.rs (limited to 'ext/cron/interface.rs') diff --git a/ext/cron/interface.rs b/ext/cron/interface.rs new file mode 100644 index 000000000..c70988788 --- /dev/null +++ b/ext/cron/interface.rs @@ -0,0 +1,23 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use async_trait::async_trait; +use deno_core::error::AnyError; + +pub trait CronHandler { + type EH: CronHandle + 'static; + + fn create(&self, spec: CronSpec) -> Result; +} + +#[async_trait(?Send)] +pub trait CronHandle { + async fn next(&self, prev_success: bool) -> Result; + fn close(&self); +} + +#[derive(Clone)] +pub struct CronSpec { + pub name: String, + pub cron_schedule: String, + pub backoff_schedule: Option>, +} -- cgit v1.2.3