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