MDL-84442 core_task: Add finalise log param to task failers

This commit is contained in:
Benjamin Walker
2025-04-22 09:29:50 +10:00
parent 2ddab5548f
commit b037708523
3 changed files with 132 additions and 6 deletions
+18 -6
View File
@@ -1082,14 +1082,17 @@ class manager {
* This function indicates that an adhoc task was not completed successfully and should be retried.
*
* @param \core\task\adhoc_task $task
* @param bool $finaliselog finalise the log of the current running task
*/
public static function adhoc_task_failed(adhoc_task $task) {
public static function adhoc_task_failed(adhoc_task $task, bool $finaliselog = true) {
global $DB;
$clock = \core\di::get(\core\clock::class);
// Finalise the log output.
logmanager::finalise_log(true);
if ($finaliselog) {
logmanager::finalise_log(true);
}
$delay = $task->get_fail_delay();
@@ -1192,14 +1195,17 @@ class manager {
* This function indicates that a scheduled task was not completed successfully and should be retried.
*
* @param \core\task\scheduled_task $task
* @param bool $finaliselog finalise the log of the current running task
*/
public static function scheduled_task_failed(scheduled_task $task) {
public static function scheduled_task_failed(scheduled_task $task, bool $finaliselog = true) {
global $DB;
$clock = \core\di::get(\core\clock::class);
// Finalise the log output.
logmanager::finalise_log(true);
if ($finaliselog) {
logmanager::finalise_log(true);
}
$delay = $task->get_fail_delay();
@@ -1418,7 +1424,10 @@ class manager {
$task = self::scheduled_task_from_record($taskrecord);
$task->set_lock($lock);
self::scheduled_task_failed($task);
// We have to skip log finalisation when failing the task as the finalise_log method from
// the log manager is only aware of the current running task (i.e., the cleanup task).
self::scheduled_task_failed($task, false);
} else if ($runningtask->type == 'adhoc') {
// Ad hoc tasks are removed from the DB if they finish successfully.
// If we can't re-get this task, that means it finished and was properly
@@ -1430,7 +1439,10 @@ class manager {
$task = self::adhoc_task_from_record($taskrecord);
$task->set_lock($lock);
self::adhoc_task_failed($task);
// We have to skip log finalisation when failing the task as the finalise_log method from
// the log manager is only aware of the current running task (i.e., the cleanup task).
self::adhoc_task_failed($task, false);
}
}
}