MDL-79128 adhoc_task: Implement no-retry task

Co-authored-by: Stevani Andolo <[email protected]>

Including in this commit:
 - Added a new counter called attemptsavailable for ad-hoc task
 - PHPUnit test for the new feature
This commit is contained in:
Huong Nguyen
2023-12-20 13:55:13 +07:00
parent 513f3b02c7
commit a44f14c79e
8 changed files with 173 additions and 2 deletions
+31
View File
@@ -46,6 +46,9 @@ abstract class adhoc_task extends task_base {
/** @var \core\lock\lock The concurrency task lock for this task. */
private $concurrencylock = null;
/** @var integer|null $attemptsavailable - The remaining attempts of the task, or null for unlimited. */
private $attemptsavailable = null;
/**
* Provide default implementation of the task name for backward compatibility. Extending classes are expected to implement
* this method to provide a descriptive name for the task (shown to admins)
@@ -171,4 +174,32 @@ abstract class adhoc_task extends task_base {
$this->concurrencylock->release();
}
}
/**
* Set the remaining attempts of the task.
*
* @param int|null $attemptsavailable Number of the remaining attempts of the task, or null for unlimited.
*/
public function set_attempts_available(?int $attemptsavailable): void {
$this->attemptsavailable = $attemptsavailable;
}
/**
* Get the remaining attempts of the task.
*
* @return int|null Number of the remaining attempts of the task, or null for unlimited.
*/
public function get_attempts_available(): ?int {
return $this->attemptsavailable;
}
/**
* Used to indicate if the task should be re-run if it fails.
* By default, tasks will be retried until they succeed, other tasks can override this method to change this behaviour.
*
* @return bool true if the task should be retried until it succeeds, false otherwise.
*/
public function retry_until_success(): bool {
return true;
}
}