Skip to content

Commit

Permalink
fix: schedules do not accept 5 units cron syntax on update/create any…
Browse files Browse the repository at this point in the history
…more
  • Loading branch information
rubenfiszel committed Feb 20, 2025
1 parent 5de1c3c commit c90fe38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 4 additions & 3 deletions backend/windmill-api/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async fn create_schedule(
let mut tx: Transaction<'_, Postgres> = user_db.begin(&authed).await?;

// Check schedule for error
ScheduleType::from_str(&ns.schedule, ns.cron_version.as_deref())?;
ScheduleType::from_str(&ns.schedule, ns.cron_version.as_deref(), true)?;

check_path_conflict(&mut tx, &w_id, &ns.path).await?;
check_flow_conflict(&mut tx, &w_id, &ns.path, ns.is_flow, &ns.script_path).await?;
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn edit_schedule(
let mut tx = user_db.begin(&authed).await?;

// Check schedule for error
ScheduleType::from_str(&es.schedule, es.cron_version.as_deref())?;
ScheduleType::from_str(&es.schedule, es.cron_version.as_deref(), true)?;

clear_schedule(&mut tx, path, &w_id).await?;
let schedule = sqlx::query_as::<_, Schedule>(
Expand Down Expand Up @@ -468,7 +468,8 @@ pub struct PreviewPayload {
pub async fn preview_schedule(
Json(payload): Json<PreviewPayload>,
) -> JsonResult<Vec<DateTime<Utc>>> {
let schedule = ScheduleType::from_str(&payload.schedule, payload.cron_version.as_deref())?;
let schedule =
ScheduleType::from_str(&payload.schedule, payload.cron_version.as_deref(), true)?;

let tz =
chrono_tz::Tz::from_str(&payload.timezone).map_err(|e| Error::BadRequest(e.to_string()))?;
Expand Down
14 changes: 12 additions & 2 deletions backend/windmill-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ impl ScheduleType {
}
}

pub fn from_str(schedule_str: &str, version: Option<&str>) -> Result<ScheduleType> {
pub fn from_str(
schedule_str: &str,
version: Option<&str>,
seconds_required: bool,
) -> Result<ScheduleType> {
tracing::debug!(
"Attempting to parse schedule string: {}, with version: {:?}",
schedule_str,
Expand All @@ -448,7 +452,13 @@ impl ScheduleType {
Some("v2") | Some(_) => {
// Use Croner for v2
let schedule_type_result = panic::catch_unwind(AssertUnwindSafe(|| {
Cron::new(schedule_str).with_seconds_optional().parse()
let mut croner = Cron::new(schedule_str);
if seconds_required {
croner.with_seconds_required();
} else {
croner.with_seconds_optional();
};
croner.parse()
}))
.map_err(|_| {
tracing::error!(
Expand Down
3 changes: 2 additions & 1 deletion backend/windmill-queue/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub async fn push_scheduled_job<'c>(
));
}

let sched = ScheduleType::from_str(&schedule.schedule, schedule.cron_version.as_deref())?;
let sched =
ScheduleType::from_str(&schedule.schedule, schedule.cron_version.as_deref(), false)?;

let tz = chrono_tz::Tz::from_str(&schedule.timezone)
.map_err(|e| error::Error::BadRequest(e.to_string()))?;
Expand Down

0 comments on commit c90fe38

Please sign in to comment.