MDL-70975 task: Support for limiting the number of adhoc tasks to run

* CLI adhoc_task.php: new option --taskslimit
* CLI adhoc_task.php: --execute option is implied when other options are given
* core\task\manager::get_next_adhoc_task(): new param $number
  for limiting number of tasks to run
This commit is contained in:
Srdjan
2023-04-05 11:05:18 +10:00
parent 3491ea1650
commit fa61fce08d
3 changed files with 52 additions and 25 deletions
+5
View File
@@ -226,6 +226,7 @@ class cron {
* @param int $keepalive Keep this public static function alive for N seconds and poll for new adhoc tasks.
* @param bool $checklimits Should we check limits?
* @param null|int $startprocesstime The time this process started.
* @param int|null $maxtasks Limit number of tasks to run`
* @param null|string $classname Run only tasks of this class
* @throws \moodle_exception
*/
@@ -234,6 +235,7 @@ class cron {
$keepalive = 0,
$checklimits = true,
?int $startprocesstime = null,
?int $maxtasks = null,
?string $classname = null,
): void {
// Allow a restriction on the number of adhoc task runners at once.
@@ -300,6 +302,9 @@ class cron {
self::run_inner_adhoc_task($task);
self::set_process_title("Waiting for next adhoc task");
$taskcount++;
if ($maxtasks && $taskcount >= $maxtasks) {
break;
}
unset($task);
} else {
$timeleft = $finishtime - time();