MDL-50719 cron: Fixed parallel task lock contention issues

This commit is contained in:
Brendan Heywood 2017-02-21 12:44:59 +11:00
parent 0f59b6dd75
commit 504d569b71

View File

@ -421,8 +421,16 @@ class manager {
foreach ($records as $record) {
if ($lock = $cronlockfactory->get_lock('adhoc_' . $record->id, 10)) {
if ($lock = $cronlockfactory->get_lock('adhoc_' . $record->id, 0)) {
$classname = '\\' . $record->classname;
// Safety check, see if the task has been already processed by another cron run.
$record = $DB->get_record('task_adhoc', array('id' => $record->id));
if (!$record) {
$lock->release();
continue;
}
$task = self::adhoc_task_from_record($record);
// Safety check in case the task in the DB does not match a real class (maybe something was uninstalled).
if (!$task) {
@ -472,7 +480,7 @@ class manager {
foreach ($records as $record) {
if ($lock = $cronlockfactory->get_lock(($record->classname), 10)) {
if ($lock = $cronlockfactory->get_lock(($record->classname), 0)) {
$classname = '\\' . $record->classname;
$task = self::scheduled_task_from_record($record);
// Safety check in case the task in the DB does not match a real class (maybe something was uninstalled).