mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-64454 Admin: Warning if cron does not run frequently
There is an existing warning if cron doesn't run at all (hasn't run for 24 hours). This commit adds a warning if cron hasn't run for 3 minutes, based on the recommendation that cron should run every minute.
This commit is contained in:
parent
4c5b60a0f9
commit
b18034ed67
@ -823,9 +823,10 @@ if (isset($SESSION->pluginuninstallreturn)) {
|
||||
// Print default admin page with notifications.
|
||||
$errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
|
||||
|
||||
// We make the assumption that at least one schedule task should run once per day.
|
||||
$lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}');
|
||||
$lastcron = get_config('tool_task', 'lastcronstart');
|
||||
$cronoverdue = ($lastcron < time() - 3600 * 24);
|
||||
$lastcroninterval = get_config('tool_task', 'lastcroninterval');
|
||||
$croninfrequent = !$cronoverdue && ($lastcroninterval > 200 || $lastcron < time() - 200);
|
||||
$dbproblems = $DB->diagnose();
|
||||
$maintenancemode = !empty($CFG->maintenance_enabled);
|
||||
|
||||
@ -886,4 +887,4 @@ $output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
|
||||
$maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
|
||||
$registered, $cachewarnings, $eventshandlers, $themedesignermode, $devlibdir,
|
||||
$mobileconfigured, $overridetossl, $invalidforgottenpasswordurl);
|
||||
$mobileconfigured, $overridetossl, $invalidforgottenpasswordurl, $croninfrequent);
|
||||
|
@ -281,6 +281,7 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
* @param bool $mobileconfigured Whether the mobile web services have been enabled
|
||||
* @param bool $overridetossl Whether or not ssl is being forced.
|
||||
* @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
|
||||
* @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
|
||||
*
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
@ -288,7 +289,7 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
$cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
|
||||
$buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
|
||||
$themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
|
||||
$overridetossl = false, $invalidforgottenpasswordurl = false) {
|
||||
$overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false) {
|
||||
global $CFG;
|
||||
$output = '';
|
||||
|
||||
@ -302,6 +303,7 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
$output .= $this->display_errors_warning($errorsdisplayed);
|
||||
$output .= $this->buggy_iconv_warning($buggyiconvnomb);
|
||||
$output .= $this->cron_overdue_warning($cronoverdue);
|
||||
$output .= $this->cron_infrequent_warning($croninfrequent);
|
||||
$output .= $this->db_problems($dbproblems);
|
||||
$output .= $this->maintenance_mode_warning($maintenancemode);
|
||||
$output .= $this->overridetossl_warning($overridetossl);
|
||||
@ -614,6 +616,21 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
$this->help_icon('cron', 'admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if cron is not being run frequently (recommended every minute).
|
||||
*
|
||||
* @param bool $croninfrequent
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function cron_infrequent_warning(bool $croninfrequent) : string {
|
||||
if (!$croninfrequent) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->warning(get_string('croninfrequent', 'admin') . ' ' .
|
||||
$this->help_icon('cron', 'admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if there are any problems with the DB set-up.
|
||||
* @param bool $dbproblems
|
||||
|
@ -419,6 +419,7 @@ $string['cronerrorpassword'] = 'Sorry, you have not provided a valid password to
|
||||
$string['cronremotepassword'] = 'Cron password for remote access';
|
||||
$string['cronwarning'] = 'The <a href="{$a}">cron.php maintenance script</a> has not been run for at least 24 hours.';
|
||||
$string['cronwarningcli'] = 'The cli/cron.php maintenance script has not been run for at least 24 hours.';
|
||||
$string['croninfrequent'] = 'The time between the last two runs of the cron maintenance script was over 3 minutes. We recommend configuring it to run more frequently.';
|
||||
$string['ctyperequired'] = 'The ctype PHP extension is now required by Moodle, in order to improve site performance and to offer multilingual compatibility.';
|
||||
$string['curlsecurityallowedport'] = 'cURL allowed ports list';
|
||||
$string['curlsecurityallowedportsyntax'] = 'List of port numbers that cURL can connect to. Valid entries are integer numbers only. Put each entry on a new line. If left empty, then all ports are allowed. If set, in almost all cases, both 443 and 80 should be specified for cURL to connect to standard HTTPS and HTTP ports.';
|
||||
|
@ -61,6 +61,14 @@ function cron_run() {
|
||||
$timenow = time();
|
||||
mtrace("Server Time: ".date('r', $timenow)."\n\n");
|
||||
|
||||
// Record start time and interval between the last cron runs.
|
||||
$laststart = get_config('tool_task', 'lastcronstart');
|
||||
set_config('lastcronstart', $timenow, 'tool_task');
|
||||
if ($laststart) {
|
||||
// Record the interval between last two runs (always store at least 1 second).
|
||||
set_config('lastcroninterval', max(1, $timenow - $laststart), 'tool_task');
|
||||
}
|
||||
|
||||
// Run all scheduled tasks.
|
||||
while (!\core\task\manager::static_caches_cleared_since($timenow) &&
|
||||
$task = \core\task\manager::get_next_scheduled_task($timenow)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user