Commit 4044df8b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

make cron maxrunage configurable

This is essential for server configurations that do not (or cannot) run
the cron.php every minute.  This change:

+ makes the maxrunage configurable
+ makes the configuration a default of 300 (same as current code setting)
(cherry picked from commit aa5618fb4d7bb22a77b813a735f1ae40f096a33a)

Conflicts:

	htdocs/config-defaults.php
	htdocs/lib/cron.php
parent d7adf1bc
......@@ -164,4 +164,19 @@ $cfg->accessidletimeout = 600;
// Whether to show the onlineusers sideblock
$cfg->showonlineuserssideblock = true;
// CRON job maximum run age in SECONDS
// ... Mahara decides to run a cron job only if the "next run time" is between the current date+time and (max run age) seconds ago.
//
// IMPORTANT: THIS MUST BE EQUAL TO OR GREATER THAN YOUR CRON JOB THAT HITS {$cfg->wwwroot}/lib/cron.php
// ... The setup/install instructions require you to set a server cron job to hit the cron.php.
// ... The default assumption by Mahara is that this will be every minute.
// ... Not all hosting providers will allow you to schedule a cron job every minute. Also, you may for your own purposes
// not want to have a cron job every minute for CPU / performance reasons.
//
// If this is not set properly, any cron periodicities less than your server cron periodicity will likely be perpetually skipped.
// This will be evident in cron job report that is output by your server after hitting cron.php.
//
// EXAMPLE: Your cron job hits cron.php every 15 minutes. Then $cfg->maxrunage must be 900 or greater.
$cfg->maxrunage = 300;
?>
......@@ -54,6 +54,10 @@ require_once(get_config('docroot') . 'import/lib.php');
require_once(get_config('docroot') . 'export/lib.php');
require_once(get_config('docroot') . 'lib/activity.php');
if (!$maxrunage = get_config('maxrunage')) {
$maxrunage = MAXRUNAGE;
}
// This is here for debugging purposes, it allows us to fake the time to test
// cron behaviour
if(isset($argv[1])) {
......@@ -73,7 +77,7 @@ foreach (plugin_types() as $plugintype) {
$jobs = get_records_select_array(
$plugintype . '_cron',
'nextrun >= ? AND nextrun < ?',
array(db_format_timestamp($now - MAXRUNAGE), db_format_timestamp($now)),
array(db_format_timestamp($now - $maxrunage), db_format_timestamp($now)),
'',
'plugin,callfunction,minute,hour,day,month,dayofweek,' . db_format_tsfield('nextrun')
);
......@@ -110,7 +114,7 @@ foreach (plugin_types() as $plugintype) {
$jobs = get_records_select_array(
$plugintype . '_cron',
'nextrun < ? OR nextrun IS NULL',
array(db_format_timestamp($now - MAXRUNAGE)),
array(db_format_timestamp($now - $maxrunage)),
'',
'plugin,callfunction,minute,hour,day,month,dayofweek,nextrun'
);
......@@ -140,7 +144,7 @@ foreach (plugin_types() as $plugintype) {
// and now the core ones (much simpler)
if ($jobs = get_records_select_array('cron', 'nextrun >= ? AND nextrun < ?',
array(db_format_timestamp($now - MAXRUNAGE), db_format_timestamp($now)))) {
array(db_format_timestamp($now - $maxrunage), db_format_timestamp($now)))) {
foreach ($jobs as $job) {
log_debug("Running core cron " . $job->callfunction);
......@@ -156,11 +160,11 @@ if ($jobs = get_records_select_array('cron', 'nextrun >= ? AND nextrun < ?',
// and missed ones...
if ($jobs = get_records_select_array('cron', 'nextrun < ? OR nextrun IS NULL',
array(db_format_timestamp($now - MAXRUNAGE)))) {
array(db_format_timestamp($now - $maxrunage)))) {
foreach ($jobs as $job) {
if ($job->nextrun) {
log_warn('core cronjob "' . $job->callfunction
. '" didn\'t get run because the nextrun time was too old');
. '" didn\'t get run because the nextrun time (' . $job->nextrun . ') was too old (less than ' . ($now - $maxrunage) . ')');
}
$nextrun = cron_next_run_time($now, (array)$job);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment