]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpportunisticQM/OpportunisticQMPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / OpportunisticQM / OpportunisticQMPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * PHP version 5
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @category  OpportunisticQMPlugin
22  * @package   StatusNet
23  * @author    Brion Vibber <brion@status.net>
24  * @copyright 2011 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26  * @link      http://status.net/
27  */
28
29 class OpportunisticQMPlugin extends Plugin {
30     public $qmkey = false;
31     public $secs_per_action = 1; // total seconds to run script per action
32     public $rel_to_pageload = true;  // relative to pageload or queue start
33
34     public function onRouterInitialized(URLMapper $m)
35     {
36         $m->connect('main/runqueue', array('action' => 'runqueue'));
37     }
38
39     /**
40      * When the page has finished rendering, let's do some cron jobs
41      * if we have the time.
42      */
43     public function onEndActionExecute(Action $action)
44     {
45         if ($action instanceof RunqueueAction) {
46             return true;
47         }
48
49         global $_startTime;
50
51         $args = array(
52                     'qmkey' => common_config('opportunisticqm', 'qmkey'),
53                     'max_execution_time' => $this->secs_per_action,
54                     'started_at'      => $this->rel_to_pageload ? $_startTime : null,
55                 );
56         $qm = new OpportunisticQueueManager($args); 
57         $qm->runQueue();
58         return true;
59     }
60
61     public function onPluginVersion(array &$versions)
62     {
63         $versions[] = array('name' => 'OpportunisticQM',
64                             'version' => GNUSOCIAL_VERSION,
65                             'author' => 'Mikael Nordfeldth',
66                             'homepage' => 'http://www.gnu.org/software/social/',
67                             'description' =>
68                             // TRANS: Plugin description.
69                             _m('Opportunistic queue manager plugin for background processing.'));
70         return true;
71     }
72 }