mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-22183 lib: Time settings removed for stats cron.
Old settings that should be ignored have been removed from the statistics cron code.
This commit is contained in:
parent
3ca3cc77a2
commit
4ae0691169
@ -79,7 +79,6 @@ $temp->add(new admin_setting_configselect('statsmaxruntime', new lang_string('st
|
||||
60*60*7 => '7 '.new lang_string('hours'),
|
||||
60*60*8 => '8 '.new lang_string('hours') )));
|
||||
$temp->add(new admin_setting_configtext('statsruntimedays', new lang_string('statsruntimedays', 'admin'), new lang_string('configstatsruntimedays', 'admin'), 31, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtime('statsruntimestarthour', 'statsruntimestartminute', new lang_string('statsruntimestart', 'admin'), new lang_string('configstatsruntimestart', 'admin'), array('h' => 0, 'm' => 0)));
|
||||
$temp->add(new admin_setting_configtext('statsuserthreshold', new lang_string('statsuserthreshold', 'admin'), new lang_string('configstatsuserthreshold', 'admin'), 0, PARAM_INT));
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
@ -44,28 +44,19 @@ class stats_cron_task extends scheduled_task {
|
||||
public function execute() {
|
||||
global $CFG;
|
||||
|
||||
$timenow = time();
|
||||
// Run stats as at the end because they are known to take very long time on large sites.
|
||||
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
// Check we're not before our runtime.
|
||||
$timetocheck = stats_get_base_daily() + $CFG->statsruntimestarthour * 60 * 60 + $CFG->statsruntimestartminute * 60;
|
||||
|
||||
if ($timenow > $timetocheck) {
|
||||
// Process configured number of days as max (defaulting to 31).
|
||||
$maxdays = empty($CFG->statsruntimedays) ? 31 : abs($CFG->statsruntimedays);
|
||||
if (stats_cron_daily($maxdays)) {
|
||||
if (stats_cron_weekly()) {
|
||||
if (stats_cron_monthly()) {
|
||||
stats_clean_old();
|
||||
}
|
||||
// Process configured number of days as max (defaulting to 31).
|
||||
$maxdays = empty($CFG->statsruntimedays) ? 31 : abs($CFG->statsruntimedays);
|
||||
if (stats_cron_daily($maxdays)) {
|
||||
if (stats_cron_weekly()) {
|
||||
if (stats_cron_monthly()) {
|
||||
stats_clean_old();
|
||||
}
|
||||
}
|
||||
\core_php_time_limit::raise();
|
||||
} else {
|
||||
mtrace('Next stats run after:'. userdate($timetocheck));
|
||||
}
|
||||
\core_php_time_limit::raise();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ $tasks = array(
|
||||
'classname' => 'core\task\stats_cron_task',
|
||||
'blocking' => 0,
|
||||
'minute' => '0',
|
||||
'hour' => '*',
|
||||
'hour' => '0',
|
||||
'day' => '*',
|
||||
'dayofweek' => '*',
|
||||
'month' => '*'
|
||||
|
@ -2083,5 +2083,46 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2016081700.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2016081700.02) {
|
||||
// Default schedule values.
|
||||
$hour = 0;
|
||||
$minute = 0;
|
||||
|
||||
// Get the old settings.
|
||||
if (isset($CFG->statsruntimestarthour)) {
|
||||
$hour = $CFG->statsruntimestarthour;
|
||||
}
|
||||
if (isset($CFG->statsruntimestartminute)) {
|
||||
$minute = $CFG->statsruntimestartminute;
|
||||
}
|
||||
|
||||
// Retrieve the scheduled task record first.
|
||||
$stattask = $DB->get_record('task_scheduled', array('component' => 'moodle', 'classname' => '\core\task\stats_cron_task'));
|
||||
|
||||
// Don't touch customised scheduling.
|
||||
if ($stattask && !$stattask->customised) {
|
||||
|
||||
$nextruntime = mktime($hour, $minute, 0, date('m'), date('d'), date('Y'));
|
||||
if ($nextruntime < $stattask->lastruntime) {
|
||||
// Add 24 hours to the next run time.
|
||||
$newtime = new DateTime();
|
||||
$newtime->setTimestamp($nextruntime);
|
||||
$newtime->add(new DateInterval('P1D'));
|
||||
$nextruntime = $newtime->getTimestamp();
|
||||
}
|
||||
$stattask->nextruntime = $nextruntime;
|
||||
$stattask->minute = $minute;
|
||||
$stattask->hour = $hour;
|
||||
$stattask->customised = 1;
|
||||
$DB->update_record('task_scheduled', $stattask);
|
||||
}
|
||||
// These settings are no longer used.
|
||||
unset_config('statsruntimestarthour');
|
||||
unset_config('statsruntimestartminute');
|
||||
unset_config('statslastexecution');
|
||||
|
||||
upgrade_main_savepoint(true, 2016081700.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -138,22 +138,6 @@ function stats_cron_daily($maxdays=1) {
|
||||
set_config('statslastdaily', $timestart);
|
||||
}
|
||||
|
||||
// calculate scheduled time
|
||||
$scheduledtime = stats_get_base_daily() + $CFG->statsruntimestarthour*60*60 + $CFG->statsruntimestartminute*60;
|
||||
|
||||
// Note: This will work fine for sites running cron each 4 hours or less (hopefully, 99.99% of sites). MDL-16709
|
||||
// check to make sure we're due to run, at least 20 hours after last run
|
||||
if (isset($CFG->statslastexecution) && ((time() - 20*60*60) < $CFG->statslastexecution)) {
|
||||
mtrace("...preventing stats to run, last execution was less than 20 hours ago.");
|
||||
return false;
|
||||
// also check that we are a max of 4 hours after scheduled time, stats won't run after that
|
||||
} else if (time() > $scheduledtime + 4*60*60) {
|
||||
mtrace("...preventing stats to run, more than 4 hours since scheduled time.");
|
||||
return false;
|
||||
} else {
|
||||
set_config('statslastexecution', time()); /// Grab this execution as last one
|
||||
}
|
||||
|
||||
$nextmidnight = stats_get_next_day_start($timestart);
|
||||
|
||||
// are there any days that need to be processed?
|
||||
@ -161,7 +145,6 @@ function stats_cron_daily($maxdays=1) {
|
||||
return true; // everything ok and up-to-date
|
||||
}
|
||||
|
||||
|
||||
$timeout = empty($CFG->statsmaxruntime) ? 60*60*24 : $CFG->statsmaxruntime;
|
||||
|
||||
if (!set_cron_lock('statsrunning', $now + $timeout)) {
|
||||
|
@ -61,7 +61,6 @@ class core_statslib_testcase extends advanced_testcase {
|
||||
core_date::set_default_server_timezone();
|
||||
$CFG->statsfirstrun = 'all';
|
||||
$CFG->statslastdaily = 0;
|
||||
$CFG->statslastexecution = 0;
|
||||
|
||||
// Figure out the broken day start so I can figure out when to the start time should be.
|
||||
$time = time();
|
||||
@ -74,9 +73,6 @@ class core_statslib_testcase extends advanced_testcase {
|
||||
|
||||
$shour = intval(($time - $stime) / (60*60));
|
||||
|
||||
$CFG->statsruntimestarthour = $shour;
|
||||
$CFG->statsruntimestartminute = 0;
|
||||
|
||||
if ($DB->record_exists('user', array('username' => 'user1'))) {
|
||||
return;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2016081700.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2016081700.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user