fix: schedules do not accept 5 units cron syntax on update/create anymore
This commit is contained in:
@@ -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?;
|
||||
@@ -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>(
|
||||
@@ -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()))?;
|
||||
|
||||
@@ -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,
|
||||
@@ -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!(
|
||||
|
||||
@@ -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()))?;
|
||||
|
||||
Reference in New Issue
Block a user