mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'master_MDL-67433' of https://github.com/golenkovm/moodle
This commit is contained in:
commit
92302a6faa
@ -35,10 +35,12 @@ list($options, $unrecognized) = cli_get_params(
|
|||||||
'keep-alive' => 0,
|
'keep-alive' => 0,
|
||||||
'showsql' => false,
|
'showsql' => false,
|
||||||
'showdebugging' => false,
|
'showdebugging' => false,
|
||||||
|
'ignorelimits' => false,
|
||||||
], [
|
], [
|
||||||
'h' => 'help',
|
'h' => 'help',
|
||||||
'e' => 'execute',
|
'e' => 'execute',
|
||||||
'k' => 'keep-alive',
|
'k' => 'keep-alive',
|
||||||
|
'i' => 'ignorelimits',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ Options:
|
|||||||
--showdebugging Show developer level debugging information
|
--showdebugging Show developer level debugging information
|
||||||
-e, --execute Run all queued adhoc tasks
|
-e, --execute Run all queued adhoc tasks
|
||||||
-k, --keep-alive=N Keep this script alive for N seconds and poll for new adhoc tasks
|
-k, --keep-alive=N Keep this script alive for N seconds and poll for new adhoc tasks
|
||||||
|
-i --ignorelimits Ignore task_adhoc_concurrency_limit and task_adhoc_max_runtime limits
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
\$sudo -u www-data /usr/bin/php admin/tool/task/cli/adhoc_task.php --execute
|
\$sudo -u www-data /usr/bin/php admin/tool/task/cli/adhoc_task.php --execute
|
||||||
@ -99,6 +102,8 @@ if (!empty($CFG->showcrondebugging)) {
|
|||||||
set_debugging(DEBUG_DEVELOPER, true);
|
set_debugging(DEBUG_DEVELOPER, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$checklimits = empty($options['ignorelimits']);
|
||||||
|
|
||||||
core_php_time_limit::raise();
|
core_php_time_limit::raise();
|
||||||
|
|
||||||
// Increase memory limit.
|
// Increase memory limit.
|
||||||
@ -107,45 +112,8 @@ raise_memory_limit(MEMORY_EXTRA);
|
|||||||
// Emulate normal session - we use admin account by default.
|
// Emulate normal session - we use admin account by default.
|
||||||
cron_setup_user();
|
cron_setup_user();
|
||||||
|
|
||||||
// Start output log.
|
$humantimenow = date('r', time());
|
||||||
$timestart = time();
|
$keepalive = (int)$options['keep-alive'];
|
||||||
$timenow = $timestart;
|
|
||||||
$finishtime = $timenow + (int)$options['keep-alive'];
|
|
||||||
$humantimenow = date('r', $timenow);
|
|
||||||
mtrace("Server Time: {$humantimenow}\n");
|
mtrace("Server Time: {$humantimenow}\n");
|
||||||
|
cron_run_adhoc_tasks(time(), $keepalive, $checklimits);
|
||||||
// Run all adhoc tasks.
|
|
||||||
$taskcount = 0;
|
|
||||||
$waiting = false;
|
|
||||||
while (!\core\task\manager::static_caches_cleared_since($timestart)) {
|
|
||||||
|
|
||||||
$task = \core\task\manager::get_next_adhoc_task($timenow);
|
|
||||||
|
|
||||||
if ($task) {
|
|
||||||
if ($waiting) {
|
|
||||||
cli_writeln('');
|
|
||||||
}
|
|
||||||
$waiting = false;
|
|
||||||
cron_run_inner_adhoc_task($task);
|
|
||||||
$taskcount++;
|
|
||||||
unset($task);
|
|
||||||
} else {
|
|
||||||
if (time() > $finishtime) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!$waiting) {
|
|
||||||
cli_write('Waiting for more adhoc tasks to be queued ');
|
|
||||||
} else {
|
|
||||||
cli_write('.');
|
|
||||||
}
|
|
||||||
$waiting = true;
|
|
||||||
sleep(1);
|
|
||||||
$timenow = time();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting) {
|
|
||||||
cli_writeln('');
|
|
||||||
}
|
|
||||||
|
|
||||||
mtrace("Ran {$taskcount} adhoc tasks found at {$humantimenow}");
|
|
||||||
|
|
||||||
|
@ -128,41 +128,80 @@ function cron_run_scheduled_tasks(int $timenow) {
|
|||||||
* Execute all queued adhoc tasks, applying necessary concurrency limits and time limits.
|
* Execute all queued adhoc tasks, applying necessary concurrency limits and time limits.
|
||||||
*
|
*
|
||||||
* @param int $timenow The time this process started.
|
* @param int $timenow The time this process started.
|
||||||
|
* @param int $keepalive Keep this function alive for N seconds and poll for new adhoc tasks.
|
||||||
|
* @param bool $checklimits Should we check limits?
|
||||||
*/
|
*/
|
||||||
function cron_run_adhoc_tasks(int $timenow) {
|
function cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true) {
|
||||||
// Allow a restriction on the number of adhoc task runners at once.
|
// Allow a restriction on the number of adhoc task runners at once.
|
||||||
$cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
|
$cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
|
||||||
$maxruns = get_config('core', 'task_adhoc_concurrency_limit');
|
$maxruns = get_config('core', 'task_adhoc_concurrency_limit');
|
||||||
$maxruntime = get_config('core', 'task_adhoc_max_runtime');
|
$maxruntime = get_config('core', 'task_adhoc_max_runtime');
|
||||||
|
|
||||||
$adhoclock = null;
|
if ($checklimits) {
|
||||||
for ($run = 0; $run < $maxruns; $run++) {
|
$adhoclock = null;
|
||||||
if ($adhoclock = $cronlockfactory->get_lock("adhoc_task_runner_{$run}", 1)) {
|
for ($run = 0; $run < $maxruns; $run++) {
|
||||||
break;
|
if ($adhoclock = $cronlockfactory->get_lock("adhoc_task_runner_{$run}", 1)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$adhoclock) {
|
||||||
|
mtrace("Skipping processing of adhoc tasks. Concurrency limit reached.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$adhoclock) {
|
$humantimenow = date('r', $timenow);
|
||||||
mtrace("Skipping processing of adhoc tasks. Concurrency limit reached.");
|
$finishtime = $timenow + $keepalive;
|
||||||
return;
|
$waiting = false;
|
||||||
}
|
$taskcount = 0;
|
||||||
|
|
||||||
$starttime = time();
|
|
||||||
|
|
||||||
// Run all adhoc tasks.
|
// Run all adhoc tasks.
|
||||||
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
|
while (!\core\task\manager::static_caches_cleared_since($timenow)) {
|
||||||
$task = \core\task\manager::get_next_adhoc_task(time())) {
|
|
||||||
cron_run_inner_adhoc_task($task);
|
|
||||||
unset($task);
|
|
||||||
|
|
||||||
if ((time() - $starttime) > $maxruntime) {
|
if ($checklimits && (time() - $timenow) >= $maxruntime) {
|
||||||
|
if ($waiting) {
|
||||||
|
$waiting = false;
|
||||||
|
mtrace('');
|
||||||
|
}
|
||||||
mtrace("Stopping processing of adhoc tasks as time limit has been reached.");
|
mtrace("Stopping processing of adhoc tasks as time limit has been reached.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$task = \core\task\manager::get_next_adhoc_task(time());
|
||||||
|
|
||||||
|
if ($task) {
|
||||||
|
if ($waiting) {
|
||||||
|
mtrace('');
|
||||||
|
}
|
||||||
|
$waiting = false;
|
||||||
|
cron_run_inner_adhoc_task($task);
|
||||||
|
$taskcount++;
|
||||||
|
unset($task);
|
||||||
|
} else {
|
||||||
|
if (time() >= $finishtime) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!$waiting) {
|
||||||
|
mtrace('Waiting for more adhoc tasks to be queued ', '');
|
||||||
|
} else {
|
||||||
|
mtrace('.', '');
|
||||||
|
}
|
||||||
|
$waiting = true;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the adhoc task runner lock.
|
if ($waiting) {
|
||||||
$adhoclock->release();
|
mtrace('');
|
||||||
|
}
|
||||||
|
|
||||||
|
mtrace("Ran {$taskcount} adhoc tasks found at {$humantimenow}");
|
||||||
|
|
||||||
|
if ($adhoclock) {
|
||||||
|
// Release the adhoc task runner lock.
|
||||||
|
$adhoclock->release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,8 @@ This files describes API changes in core libraries and APIs,
|
|||||||
information provided here is intended especially for developers.
|
information provided here is intended especially for developers.
|
||||||
|
|
||||||
=== 3.9 ===
|
=== 3.9 ===
|
||||||
|
* admin/tool/task/cli/adhoc_task.php now observers the concurrency limits.
|
||||||
|
If you want to get the previous (unlimited) behavior, use the --ignorelimits switch).
|
||||||
* Removed the following deprecated functions:
|
* Removed the following deprecated functions:
|
||||||
- question_add_tops
|
- question_add_tops
|
||||||
- question_is_only_toplevel_category_in_context
|
- question_is_only_toplevel_category_in_context
|
||||||
|
Loading…
x
Reference in New Issue
Block a user