fix(cron): correct false high-frequency warning for daily cron jobs

The frequency check compared two consecutive calls to
next_run_for_schedule with now and now+1s, which returned the same
next occurrence for daily schedules — making the interval appear as
0 minutes. Compare two consecutive occurrences instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
harald 2026-02-21 07:36:03 +01:00
parent 66c838c374
commit 61a998cae3

View file

@ -218,11 +218,14 @@ fn warn_if_high_frequency_agent_job(job: &CronJob) {
Schedule::Every { every_ms } => *every_ms < 5 * 60 * 1000, Schedule::Every { every_ms } => *every_ms < 5 * 60 * 1000,
Schedule::Cron { .. } => { Schedule::Cron { .. } => {
let now = Utc::now(); let now = Utc::now();
match ( match next_run_for_schedule(&job.schedule, now) {
next_run_for_schedule(&job.schedule, now), Ok(first) => {
next_run_for_schedule(&job.schedule, now + chrono::Duration::seconds(1)), // Get the occurrence *after* the first one to measure the actual interval.
) { match next_run_for_schedule(&job.schedule, first) {
(Ok(a), Ok(b)) => (b - a).num_minutes() < 5, Ok(second) => (second - first).num_minutes() < 5,
_ => false,
}
}
_ => false, _ => false,
} }
} }