MDL-70975 task: Support for running adhoc tasks by id

* CLI adhoc_task.php: new option --id
* cron::run_adhoc_task($taskid) for running tasks by id
* core\task\manager::get_adhoc_task($taskid) for retreival/locking
This commit is contained in:
Srdjan
2023-04-05 10:55:18 +10:00
parent fba0658777
commit 9405b5aa6d
5 changed files with 112 additions and 31 deletions
+15
View File
@@ -327,6 +327,21 @@ class cron {
}
}
/**
* Execute a (failed) adhoc task.
*
* @param int $taskid
*/
public static function run_adhoc_task(int $taskid): void {
$task = \core\task\manager::get_adhoc_task($taskid);
if (!$task->get_fail_delay() && $task->get_next_run_time() > time()) {
throw new \moodle_exception('wontrunfuturescheduledtask');
}
self::run_inner_adhoc_task($task);
self::set_process_title("Running adhoc task $taskid");
}
/**
* Shared code that handles running of a single scheduled task within the cron.
*