]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16709. Improve scheduling of stats. They only will run if:
authorstronk7 <stronk7>
Mon, 13 Oct 2008 23:24:45 +0000 (23:24 +0000)
committerstronk7 <stronk7>
Mon, 13 Oct 2008 23:24:45 +0000 (23:24 +0000)
- 20 hours has passes since last execution.
- We are in a 4 hours time window since last scheduled time.
Should work for 99.99% os sites (running cron in < 4h intervals)

Merged from 19_STABLE

lib/statslib.php

index 42d08a2e7eaaf9d4f8b44d7f569426a0a4fbf273..61547f0e29e5c7773a93771f200d1af05587d465 100644 (file)
@@ -86,6 +86,22 @@ 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 (hoppefully, 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) and ((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?
@@ -93,6 +109,7 @@ 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)) {