Merge branch 'master_MDL-67485' of https://github.com/golenkovm/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 9 Jan 2020 04:39:28 +0000 (12:39 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 9 Jan 2020 04:39:28 +0000 (12:39 +0800)
1  2 
lib/classes/task/manager.php
lib/cronlib.php

@@@ -552,10 -552,10 +552,11 @@@ class manager 
       * {@link adhoc_task_failed} or {@link adhoc_task_complete} to release the lock and reschedule the task.
       *
       * @param int $timestart
 +     * @param bool $checklimits Should we check limits?
       * @return \core\task\adhoc_task or null if not found
+      * @throws \moodle_exception
       */
 -    public static function get_next_adhoc_task($timestart) {
 +    public static function get_next_adhoc_task($timestart, $checklimits = true) {
          global $DB;
  
          $where = '(nextruntime IS NULL OR nextruntime < :timestart1)';
diff --cc lib/cronlib.php
@@@ -174,7 -172,15 +178,15 @@@ function cron_run_adhoc_tasks(int $time
              break;
          }
  
-         $task = \core\task\manager::get_next_adhoc_task(time(), $checklimits);
+         try {
 -            $task = \core\task\manager::get_next_adhoc_task(time());
++            $task = \core\task\manager::get_next_adhoc_task(time(), $checklimits);
+         } catch (Exception $e) {
+             if ($adhoclock) {
+                 // Release the adhoc task runner lock.
+                 $adhoclock->release();
+             }
+             throw $e;
+         }
  
          if ($task) {
              if ($waiting) {