MDL-47529 task: Do not use lock when updating task records
This commit is contained in:
@@ -85,53 +85,31 @@ class manager {
|
||||
*/
|
||||
public static function reset_scheduled_tasks_for_component($componentname) {
|
||||
global $DB;
|
||||
$cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
|
||||
|
||||
if (!$cronlock = $cronlockfactory->get_lock('core_cron', 10, 60)) {
|
||||
throw new \moodle_exception('locktimeout');
|
||||
}
|
||||
$tasks = self::load_default_scheduled_tasks_for_component($componentname);
|
||||
|
||||
$tasklocks = array();
|
||||
foreach ($tasks as $taskid => $task) {
|
||||
$classname = get_class($task);
|
||||
if (strpos($classname, '\\') !== 0) {
|
||||
$classname = '\\' . $classname;
|
||||
}
|
||||
|
||||
// For tasks, the first run should also follow the schedule.
|
||||
$task->set_next_run_time($task->get_next_scheduled_time());
|
||||
|
||||
// If there is an existing task with a custom schedule, do not override it.
|
||||
$currenttask = self::get_scheduled_task($classname);
|
||||
if ($currenttask && $currenttask->is_customised()) {
|
||||
$tasks[$taskid] = $currenttask;
|
||||
}
|
||||
|
||||
if (!$lock = $cronlockfactory->get_lock($classname, 10, 60)) {
|
||||
// Could not get all the locks required - release all locks and fail.
|
||||
foreach ($tasklocks as $tasklock) {
|
||||
$tasklock->release();
|
||||
if ($currenttask = self::get_scheduled_task($classname)) {
|
||||
if ($currenttask->is_customised()) {
|
||||
// If there is an existing task with a custom schedule, do not override it.
|
||||
continue;
|
||||
}
|
||||
$cronlock->release();
|
||||
throw new \moodle_exception('locktimeout');
|
||||
|
||||
// Update the record from the default task data.
|
||||
self::configure_scheduled_task($task);
|
||||
} else {
|
||||
// Ensure that the first run follows the schedule.
|
||||
$task->set_next_run_time($task->get_next_scheduled_time());
|
||||
|
||||
// Insert the new task in the database.
|
||||
$record = self::record_from_scheduled_task($task);
|
||||
$DB->insert_record('task_scheduled', $record);
|
||||
}
|
||||
$tasklocks[] = $lock;
|
||||
}
|
||||
|
||||
// Got a lock on cron and all the tasks for this component, time to reset the config.
|
||||
$DB->delete_records('task_scheduled', array('component' => $componentname));
|
||||
foreach ($tasks as $task) {
|
||||
$record = self::record_from_scheduled_task($task);
|
||||
$DB->insert_record('task_scheduled', $record);
|
||||
}
|
||||
|
||||
// Release the locks.
|
||||
foreach ($tasklocks as $tasklock) {
|
||||
$tasklock->release();
|
||||
}
|
||||
|
||||
$cronlock->release();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user