MDL-59594 cron: Allow graceful exit of cron and adhoc task cli's

This commit is contained in:
Brendan Heywood
2020-01-12 01:24:03 +11:00
parent 176b5202e0
commit b15c53f4fa
3 changed files with 8 additions and 2 deletions
+2
View File
@@ -74,4 +74,6 @@ if ($options['stop']) {
die;
}
\core\local\cli\shutdown::script_supports_graceful_exit();
cron_run();
+2
View File
@@ -115,5 +115,7 @@ cron_setup_user();
$humantimenow = date('r', time());
$keepalive = (int)$options['keep-alive'];
\core\local\cli\shutdown::script_supports_graceful_exit();
mtrace("Server Time: {$humantimenow}\n");
cron_run_adhoc_tasks(time(), $keepalive, $checklimits);
+4 -2
View File
@@ -114,7 +114,8 @@ function cron_run_scheduled_tasks(int $timenow) {
// Run all scheduled tasks.
try {
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
while (!\core\local\cli\shutdown::should_gracefully_exit() &&
!\core\task\manager::static_caches_cleared_since($timenow) &&
$task = \core\task\manager::get_next_scheduled_task($timenow)) {
cron_run_inner_scheduled_task($task);
unset($task);
@@ -167,7 +168,8 @@ function cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true)
$taskcount = 0;
// Run all adhoc tasks.
while (!\core\task\manager::static_caches_cleared_since($timenow)) {
while (!\core\local\cli\shutdown::should_gracefully_exit() &&
!\core\task\manager::static_caches_cleared_since($timenow)) {
if ($checklimits && (time() - $timenow) >= $maxruntime) {
if ($waiting) {