Skip to content

Commit a5e212d

Browse files
committed
fix(cron): compute correctly time boundaries avoiding re-triggering
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 50c6c1d commit a5e212d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

core/services/jobs/dispatcher.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ func (d *Dispatcher) isCronDue(task TaskRecord) bool {
459459
return true
460460
}
461461

462+
// Compute the cron interval from two consecutive ticks after the last job.
463+
// Use elapsed time since the last job rather than clock-aligned ticks to
464+
// avoid re-triggering when the job was created shortly before a tick boundary.
462465
nextRun := schedule.Next(lastJob.CreatedAt)
463-
return time.Now().After(nextRun)
466+
minInterval := schedule.Next(nextRun).Sub(nextRun)
467+
return time.Since(lastJob.CreatedAt) >= minInterval
464468
}

core/services/nodes/file_transfer_server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,15 @@ func validatePathInDir(targetPath, baseDir string) error {
309309
}
310310
realTarget, err := filepath.EvalSymlinks(absTarget)
311311
if err != nil {
312-
realTarget = filepath.Clean(absTarget)
312+
// File may not exist yet (e.g. upload). Resolve the parent directory
313+
// and re-join the filename so symlinks like /tmp -> /private/tmp on
314+
// macOS are still resolved correctly.
315+
parentReal, perr := filepath.EvalSymlinks(filepath.Dir(absTarget))
316+
if perr == nil {
317+
realTarget = filepath.Join(parentReal, filepath.Base(absTarget))
318+
} else {
319+
realTarget = filepath.Clean(absTarget)
320+
}
313321
}
314322

315323
if !strings.HasPrefix(realTarget, realBase+string(filepath.Separator)) && realTarget != realBase {

0 commit comments

Comments
 (0)