MDL-67485 task: Release the task runner lock before throwing exception.

This commit is contained in:
Mikhail Golenkov
2020-01-09 15:09:33 +11:00
parent b2c0237ae8
commit b3e0d3edec
2 changed files with 28 additions and 20 deletions
+2
View File
@@ -478,6 +478,7 @@ class manager {
*
* @param int $timestart
* @return \core\task\adhoc_task or null if not found
* @throws \moodle_exception
*/
public static function get_next_adhoc_task($timestart) {
global $DB;
@@ -532,6 +533,7 @@ class manager {
*
* @param int $timestart - The start of the cron process - do not repeat any tasks that have been run more recently than this.
* @return \core\task\scheduled_task or null
* @throws \moodle_exception
*/
public static function get_next_scheduled_task($timestart) {
global $DB;
+26 -20
View File
@@ -87,6 +87,7 @@ function cron_run() {
* Execute all queued scheduled tasks, applying necessary concurrency limits and time limits.
*
* @param int $timenow The time this process started.
* @throws \moodle_exception
*/
function cron_run_scheduled_tasks(int $timenow) {
// Allow a restriction on the number of scheduled task runners at once.
@@ -109,25 +110,28 @@ function cron_run_scheduled_tasks(int $timenow) {
$starttime = time();
// Run all scheduled tasks.
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
$task = \core\task\manager::get_next_scheduled_task($timenow)) {
cron_run_inner_scheduled_task($task);
unset($task);
try {
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
$task = \core\task\manager::get_next_scheduled_task($timenow)) {
cron_run_inner_scheduled_task($task);
unset($task);
if ((time() - $starttime) > $maxruntime) {
mtrace("Stopping processing of scheduled tasks as time limit has been reached.");
break;
if ((time() - $starttime) > $maxruntime) {
mtrace("Stopping processing of scheduled tasks as time limit has been reached.");
break;
}
}
} finally {
// Release the scheduled task runner lock.
$scheduledlock->release();
}
// Release the scheduled task runner lock.
$scheduledlock->release();
}
/**
* Execute all queued adhoc tasks, applying necessary concurrency limits and time limits.
*
* @param int $timenow The time this process started.
* @throws \moodle_exception
*/
function cron_run_adhoc_tasks(int $timenow) {
// Allow a restriction on the number of adhoc task runners at once.
@@ -150,19 +154,21 @@ function cron_run_adhoc_tasks(int $timenow) {
$starttime = time();
// Run all adhoc tasks.
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
$task = \core\task\manager::get_next_adhoc_task(time())) {
cron_run_inner_adhoc_task($task);
unset($task);
try {
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
$task = \core\task\manager::get_next_adhoc_task(time())) {
cron_run_inner_adhoc_task($task);
unset($task);
if ((time() - $starttime) > $maxruntime) {
mtrace("Stopping processing of adhoc tasks as time limit has been reached.");
break;
if ((time() - $starttime) > $maxruntime) {
mtrace("Stopping processing of adhoc tasks as time limit has been reached.");
break;
}
}
} finally {
// Release the adhoc task runner lock.
$adhoclock->release();
}
// Release the adhoc task runner lock.
$adhoclock->release();
}
/**