]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpportunisticQM/OpportunisticQMPlugin.php
Debugging log fix.
[quix0rs-gnu-social.git] / plugins / OpportunisticQM / OpportunisticQMPlugin.php
1 <?php
2
3 class OpportunisticQMPlugin extends Plugin {
4     public $qmkey = false;
5     public $secs_per_action = 1; // total seconds to run script per action
6     public $rel_to_pageload = true;  // relative to pageload or queue start
7     public $verbosity = 1;
8
9     public function onRouterInitialized($m)
10     {
11         $m->connect('main/runqueue', array('action' => 'runqueue'));
12     }
13
14     /**
15      * When the page has finished rendering, let's do some cron jobs
16      * if we have the time.
17      */
18     public function onEndActionExecute(Action $action)
19     {
20         if ($action instanceof RunqueueAction) {
21             return true;
22         }
23
24         global $_startTime;
25
26         $args = array(
27                     'qmkey' => common_config('opportunisticqm', 'qmkey'),
28                     'max_execution_time' => $this->secs_per_action,
29                     'started_at'      => $this->rel_to_pageload ? $_startTime : null,
30                     'verbosity'          => $this->verbosity,
31                 );
32         $qm = new OpportunisticQueueManager($args); 
33         $qm->runQueue();
34         return true;
35     }
36
37     public function onPluginVersion(array &$versions)
38     {
39         $versions[] = array('name' => 'OpportunisticQM',
40                             'version' => GNUSOCIAL_VERSION,
41                             'author' => 'Mikael Nordfeldth',
42                             'homepage' => 'http://www.gnu.org/software/social/',
43                             'description' =>
44                             // TRANS: Plugin description.
45                             _m('Opportunistic queue manager plugin for background processing.'));
46         return true;
47     }
48 }