From 3ba36a9082e4a8e8968e8490f7b4a4347690b4a2 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 25 Apr 2024 14:55:18 +0200 Subject: [PATCH] MDL-81689 tests: Check task DB record for nextruntime --- lib/classes/task/manager.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 83d4736a5fe..951a18e8bbb 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -807,8 +807,11 @@ class manager { if ($lock = $cronlockfactory->get_lock('adhoc_' . $record->id, 0)) { - // Safety check, see if the task has been already processed by another cron run. - $record = $DB->get_record('task_adhoc', array('id' => $record->id)); + // Safety check, see if the task has already been processed by another cron run (or attempted and failed). + // If another cron run attempted to process the task and failed, nextruntime will be in the future. + $record = $DB->get_record_select('task_adhoc', + "id = :id AND nextruntime < :timestart", + ['id' => $record->id, 'timestart' => $timestart]); if (!$record) { $lock->release(); unset(self::$miniqueue[$taskid]);