MDL-79130 task_adhoc: Defined max retry constant

This commit is contained in:
Stevani Andolo 2023-11-21 13:38:20 +08:00
parent 9587029a46
commit 2425e07db3
2 changed files with 9 additions and 4 deletions

View File

@ -55,6 +55,11 @@ class manager {
*/
const ADHOC_TASK_FAILED_RETENTION = 4 * WEEKSECS;
/**
* @var int Used for max retry.
*/
const MAX_RETRY = 9;
/**
* @var array A cached queue of adhoc tasks
*/
@ -236,7 +241,7 @@ class manager {
}
// Check if the task is allowed to be retried or not.
$record->attemptsavailable = $task->retry_until_success() ? null : 1;
$record->attemptsavailable = $task->retry_until_success() ? self::MAX_RETRY : 1;
// Check if the same task is already scheduled.
if ($checkforexisting && self::task_is_scheduled($task)) {
@ -1128,7 +1133,7 @@ class manager {
$task->set_pid();
$task->set_next_run_time(time() + $delay);
$task->set_fail_delay($delay);
if (!$task->retry_until_success() && $task->get_attempts_available() > 0) {
if ($task->get_attempts_available() > 0) {
$task->set_attempts_available($task->get_attempts_available() - 1);
}
$record = self::record_from_adhoc_task($task);

View File

@ -164,7 +164,7 @@ class adhoc_task_test extends \advanced_testcase {
return: 'attemptsavailable',
conditions: ['id' => $taskid1]
);
$this->assertNull(actual: $attemptsavailable);
$this->assertEquals(expected: manager::MAX_RETRY, actual: $attemptsavailable);
// Get the task from the scheduler, execute it, and mark it as failed.
$task = manager::get_next_adhoc_task(timestart: $now);
@ -178,7 +178,7 @@ class adhoc_task_test extends \advanced_testcase {
return: 'attemptsavailable',
conditions: ['id' => $taskid1]
);
$this->assertNull(actual: $attemptsavailable);
$this->assertEquals(expected: manager::MAX_RETRY - 1, actual: $attemptsavailable);
// Create a no-retry adhoc task.
$now = time();