Fix failed manual run pushing next_run and premature last_run in UI

- record_failure() now only recomputes next_run when the job is already
  overdue (next_run <= now), preserving the scheduled fire time when a
  manual run fails before the job's natural next_run
- Remove premature job.last_run update in scheduler.js — the job runs
  asynchronously so last_run should only reflect the server-side
  completion timestamp on the next data refresh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
vnz
2026-03-19 04:24:39 +01:00
co-authored by Claude Opus 4.6
parent 7b1057df0c
commit 2915cb2113
2 changed files with 10 additions and 2 deletions
@@ -204,7 +204,9 @@ function schedulerPage() {
var result = await OpenFangAPI.post('/api/cron/jobs/' + job.id + '/run', {});
if (result.status === 'triggered' || result.status === 'completed') {
OpenFangToast.success('Job "' + (job.name || 'job') + '" triggered');
job.last_run = new Date().toISOString();
// Don't update job.last_run here — the job runs asynchronously in the
// background. The real last_run is set by the server on completion and
// will appear on the next data refresh.
} else {
OpenFangToast.error('Run failed: ' + (result.error || 'Unknown error'));
}
+7 -1
View File
@@ -387,7 +387,13 @@ impl CronScheduler {
);
meta.job.enabled = false;
} else {
meta.job.next_run = Some(compute_next_run_after(&meta.job.schedule, Utc::now()));
// Only recompute next_run if the job was already overdue. This
// preserves the scheduled fire time when a manual (on-demand) run
// fails before the job's natural next_run.
let now = Utc::now();
if meta.job.next_run.map(|t| t <= now).unwrap_or(true) {
meta.job.next_run = Some(compute_next_run_after(&meta.job.schedule, now));
}
}
}
}