2013-11-20 20:20:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class OpportunisticQMPlugin extends Plugin {
|
2019-09-02 21:39:55 +01:00
|
|
|
const PLUGIN_VERSION = '3.0.0';
|
2019-06-03 01:56:52 +01:00
|
|
|
|
2013-11-20 20:20:42 +00:00
|
|
|
public $qmkey = false;
|
2019-09-02 21:39:55 +01:00
|
|
|
public $secs_per_action = 1; // total seconds to run script per action
|
2013-11-20 20:20:42 +00:00
|
|
|
public $rel_to_pageload = true; // relative to pageload or queue start
|
2016-01-09 23:51:25 +00:00
|
|
|
public $verbosity = 1;
|
2013-11-20 20:20:42 +00:00
|
|
|
|
|
|
|
public function onRouterInitialized($m)
|
|
|
|
{
|
2019-09-02 21:39:55 +01:00
|
|
|
$m->connect('main/runqueue', ['action' => 'runqueue']);
|
2013-11-20 20:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the page has finished rendering, let's do some cron jobs
|
|
|
|
* if we have the time.
|
|
|
|
*/
|
2015-02-27 11:11:43 +00:00
|
|
|
public function onEndActionExecute(Action $action)
|
2013-11-20 20:20:42 +00:00
|
|
|
{
|
|
|
|
if ($action instanceof RunqueueAction) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $_startTime;
|
|
|
|
|
2019-09-02 21:39:55 +01:00
|
|
|
$args = ['qmkey' => common_config('opportunisticqm', 'qmkey'),
|
|
|
|
'max_execution_time' => $this->secs_per_action,
|
|
|
|
'started_at' => $this->rel_to_pageload ? $_startTime : null,
|
|
|
|
'verbosity' => $this->verbosity];
|
|
|
|
$qm = new OpportunisticQueueManager($args);
|
2013-11-20 20:20:42 +00:00
|
|
|
$qm->runQueue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-12 15:03:30 +01:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2013-11-20 20:20:42 +00:00
|
|
|
{
|
2019-09-02 21:39:55 +01:00
|
|
|
$versions[] = array('name' => 'OpportunisticQM',
|
|
|
|
'version' => self::PLUGIN_VERSION,
|
|
|
|
'author' => 'Mikael Nordfeldth',
|
|
|
|
'homepage' => 'http://www.gnu.org/software/social/',
|
2013-11-20 20:20:42 +00:00
|
|
|
'description' =>
|
|
|
|
// TRANS: Plugin description.
|
|
|
|
_m('Opportunistic queue manager plugin for background processing.'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|