From 75db8e2e8bc5ba519f9637e1a5f448198e3c7bbc Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Wed, 13 Nov 2024 20:27:13 -0500 Subject: [PATCH] queue --- backend/Cargo.lock | 1 + backend/windmill-queue/Cargo.toml | 3 ++- backend/windmill-queue/src/schedule.rs | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 5bf691ecd7..e9cccc0a9e 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -11034,6 +11034,7 @@ dependencies = [ "chrono", "chrono-tz 0.10.0", "cron", + "croner", "futures-core", "hex", "hmac", diff --git a/backend/windmill-queue/Cargo.toml b/backend/windmill-queue/Cargo.toml index 435b7c71f7..46a3d9286b 100644 --- a/backend/windmill-queue/Cargo.toml +++ b/backend/windmill-queue/Cargo.toml @@ -42,4 +42,5 @@ async-recursion.workspace = true bigdecimal.workspace = true axum.workspace = true serde_urlencoded.workspace = true -regex.workspace = true \ No newline at end of file +regex.workspace = true +croner = "2.0.6" diff --git a/backend/windmill-queue/src/schedule.rs b/backend/windmill-queue/src/schedule.rs index d39053c3c7..1aa3811c57 100644 --- a/backend/windmill-queue/src/schedule.rs +++ b/backend/windmill-queue/src/schedule.rs @@ -25,6 +25,7 @@ use windmill_common::{ users::username_to_permissioned_as, utils::{now_from_db, StripPath}, }; +use croner::Cron; pub async fn push_scheduled_job<'c, R: rsmq_async::RsmqConnection + Send + 'c>( db: &DB, @@ -39,7 +40,9 @@ pub async fn push_scheduled_job<'c, R: rsmq_async::RsmqConnection + Send + 'c>( )); } - let sched = cron::Schedule::from_str(schedule.schedule.as_ref()) + let sched = Cron::new(schedule.schedule.as_ref()) + .with_seconds_optional() + .parse() .map_err(|e| error::Error::BadRequest(e.to_string()))?; let tz = chrono_tz::Tz::from_str(&schedule.timezone) @@ -65,8 +68,8 @@ pub async fn push_scheduled_job<'c, R: rsmq_async::RsmqConnection + Send + 'c>( }; let next = sched - .after(&starting_from) - .next() + // `false` means not inclusive of `starting_from` + .find_next_occurrence(&starting_from, false) .expect("a schedule should have a next event"); // println!("next event ({:?}): {}", tz, next);