Skip to content

Commit

Permalink
MDL-64454 Admin: Configuration option for cron frequency warning
Browse files Browse the repository at this point in the history
This change makes the warning time (default 200 seconds) configurable
in config.php.
  • Loading branch information
sammarshallou committed Jan 14, 2019
1 parent b18034e commit ff13ae5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@
$lastcron = get_config('tool_task', 'lastcronstart');
$cronoverdue = ($lastcron < time() - 3600 * 24);
$lastcroninterval = get_config('tool_task', 'lastcroninterval');
$croninfrequent = !$cronoverdue && ($lastcroninterval > 200 || $lastcron < time() - 200);
$expectedfrequency = $CFG->expectedcronfrequency ?? 200;
$croninfrequent = !$cronoverdue && ($lastcroninterval > $expectedfrequency || $lastcron < time() - $expectedfrequency);
$dbproblems = $DB->diagnose();
$maintenancemode = !empty($CFG->maintenance_enabled);

Expand Down
5 changes: 4 additions & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,14 @@ public function cron_overdue_warning($cronoverdue) {
* @return string HTML to output.
*/
public function cron_infrequent_warning(bool $croninfrequent) : string {
global $CFG;

if (!$croninfrequent) {
return '';
}

return $this->warning(get_string('croninfrequent', 'admin') . '&nbsp;' .
$expectedfrequency = $CFG->expectedcronfrequency ?? 200;
return $this->warning(get_string('croninfrequent', 'admin', $expectedfrequency) . '&nbsp;' .
$this->help_icon('cron', 'admin'));
}

Expand Down
6 changes: 6 additions & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@
//
// $CFG->disablelogintoken = true;
//
// Moodle 3.7+ checks that cron is running frequently. If the time between cron runs
// is greater than this value (in seconds), you get a warning on the admin page. (This
// setting only controls whether or not the warning appears, it has no other effect.)
//
// $CFG->expectedcronfrequency = 200;
//
//=========================================================================
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
//=========================================================================
Expand Down
2 changes: 1 addition & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@
$string['cronclionly'] = 'Cron execution via command line only';
$string['cronerrorclionly'] = 'Sorry, internet access to this page has been disabled by the administrator.';
$string['cronerrorpassword'] = 'Sorry, you have not provided a valid password to access this page';
$string['croninfrequent'] = 'The time between the last two runs of the cron maintenance script was over {$a} seconds. We recommend configuring it to run more frequently.';
$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.';
Expand Down

0 comments on commit ff13ae5

Please sign in to comment.