3 * GNU social cron-on-visit class
5 * Keeps track, through Config dataobject class, of relative time since the
6 * last run in order to to run event handlers with certain intervals.
10 * @author Mikael Nordfeldth <mmn@hethane.se>
11 * @copyright 2013 Free Software Foundation, Inc.
12 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
13 * @link http://status.net/
18 * Will call events as close as it gets to one hour. Event handlers
19 * which use this MUST be as quick as possible, maybe only adding a
20 * queue item to be handled later or something. Otherwise execution
21 * will timeout for PHP - or at least cause unnecessary delays for
22 * the unlucky user who visits the site exactly at one of these events.
24 public function callTimedEvents()
26 $timers = array('minutely' => 60, // this is NOT guaranteed to run every minute (only on busy sites)
31 foreach($timers as $name=>$interval) {
34 $lastrun = new Config();
35 $lastrun->section = 'cron';
36 $lastrun->setting = 'last_' . $name;
37 $found = $lastrun->find(true);
40 $lastrun->value = time();
41 if ($lastrun->insert() === false) {
42 common_log(LOG_WARNING, "Could not save 'cron' setting '{$name}'");
46 } elseif ($lastrun->value < time() - $interval) {
47 $orig = clone($lastrun);
48 $lastrun->value = time();
49 $lastrun->update($orig);
54 // such as CronHourly, CronDaily, CronWeekly
55 Event::handle('Cron' . ucfirst($name));