MDL-63580 core_task: Deprecation cron_run_single_task and run_from_cli

Also we have move the functions in \tool_task\run_from_cli to \core\task\manager
and we have deprecated that class.
This commit is contained in:
cescobedo
2020-05-11 10:53:23 +02:00
parent 079736ccb3
commit db15746c2d
7 changed files with 90 additions and 112 deletions
-83
View File
@@ -365,89 +365,6 @@ function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) {
get_mailer('close');
}
/**
* Runs a single cron task. This function assumes it is displaying output in pseudo-CLI mode.
*
* The function will fail if the task is disabled.
*
* Warning: Because this function closes the browser session, it may not be safe to continue
* with other processing (other than displaying the rest of the page) after using this function!
*
* @param \core\task\scheduled_task $task Task to run
* @return bool True if cron run successful
*/
function cron_run_single_task(\core\task\scheduled_task $task) {
global $CFG, $DB, $USER;
if (CLI_MAINTENANCE) {
echo "CLI maintenance mode active, cron execution suspended.\n";
return false;
}
if (moodle_needs_upgrading()) {
echo "Moodle upgrade pending, cron execution suspended.\n";
return false;
}
// Check task and component is not disabled.
$taskname = get_class($task);
if ($task->get_disabled()) {
echo "Task is disabled ($taskname).\n";
return false;
}
$component = $task->get_component();
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
if ($plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled()) {
echo "Component is not enabled ($component).\n";
return false;
}
}
// Enable debugging features as per config settings.
if (!empty($CFG->showcronsql)) {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
set_debugging(DEBUG_DEVELOPER, true);
}
// Increase time and memory limits.
core_php_time_limit::raise();
raise_memory_limit(MEMORY_EXTRA);
// Switch to admin account for cron tasks, but close the session so we don't send this stuff
// to the browser.
session_write_close();
$realuser = clone($USER);
cron_setup_user(null, null, true);
// Get lock for cron task.
$cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
if (!$cronlock = $cronlockfactory->get_lock('core_cron', 1)) {
echo "Unable to get cron lock.\n";
return false;
}
if (!$lock = $cronlockfactory->get_lock($taskname, 1)) {
$cronlock->release();
echo "Unable to get task lock for $taskname.\n";
return false;
}
$task->set_lock($lock);
if (!$task->is_blocking()) {
$cronlock->release();
} else {
$task->set_cron_lock($cronlock);
}
// Run actual tasks.
cron_run_inner_scheduled_task($task);
// Go back to real user account.
cron_setup_user($realuser, null, true);
return true;
}
/**
* Output some standard information during cron runs. Specifically current time
* and memory usage. This method also does gc_collect_cycles() (before displaying