From 73b32a2506f67a19db7f6be05ad4bf4c289b8c90 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Mon, 17 Feb 2025 18:53:45 +0100 Subject: [PATCH] fix(TimedJob): Add time leeway in start condition Since cron jobs may not always run at the very same second, e.g. at 10:45:16 and at 10:50:14, some jobs (depending on the interval) that should actually run wouldn't be started when exactly comparing the interval with the time of the last run. Therefore, allow a time leeway of a few seconds. Signed-off-by: Matthias Meusburger --- lib/public/BackgroundJob/TimedJob.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/public/BackgroundJob/TimedJob.php b/lib/public/BackgroundJob/TimedJob.php index 85ca34665b41c..c68329977d413 100644 --- a/lib/public/BackgroundJob/TimedJob.php +++ b/lib/public/BackgroundJob/TimedJob.php @@ -18,6 +18,7 @@ * @since 15.0.0 */ abstract class TimedJob extends Job { + protected static int $lastRunCheckMargin = 20; protected int $interval = 0; protected int $timeSensitivity = IJob::TIME_SENSITIVE; @@ -81,7 +82,7 @@ final public function execute(IJobList $jobList, ?ILogger $logger = null) { * @since 25.0.0 */ final public function start(IJobList $jobList): void { - if (($this->time->getTime() - $this->lastRun) > $this->interval) { + if (($this->time->getTime() - $this->lastRun) > $this->interval - self::$lastRunCheckMargin) { if ($this->interval >= 12 * 60 * 60 && $this->isTimeSensitive()) { Server::get(LoggerInterface::class)->debug('TimedJob ' . get_class($this) . ' has a configured interval of ' . $this->interval . ' seconds, but is also marked as time sensitive. Please consider marking it as time insensitive to allow more sensitive jobs to run when needed.'); }