OpportunisticQMPlugin.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class OpportunisticQMPlugin extends Plugin {
  3. const PLUGIN_VERSION = '2.0.0';
  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. public function onRouterInitialized($m)
  9. {
  10. $m->connect('main/runqueue', array('action' => 'runqueue'));
  11. }
  12. /**
  13. * When the page has finished rendering, let's do some cron jobs
  14. * if we have the time.
  15. */
  16. public function onEndActionExecute(Action $action)
  17. {
  18. if ($action instanceof RunqueueAction) {
  19. return true;
  20. }
  21. global $_startTime;
  22. $args = array(
  23. 'qmkey' => common_config('opportunisticqm', 'qmkey'),
  24. 'max_execution_time' => $this->secs_per_action,
  25. 'started_at' => $this->rel_to_pageload ? $_startTime : null,
  26. 'verbosity' => $this->verbosity,
  27. );
  28. $qm = new OpportunisticQueueManager($args);
  29. $qm->runQueue();
  30. return true;
  31. }
  32. public function onPluginVersion(array &$versions)
  33. {
  34. $versions[] = array('name' => 'OpportunisticQM',
  35. 'version' => self::PLUGIN_VERSION,
  36. 'author' => 'Mikael Nordfeldth',
  37. 'homepage' => 'http://www.gnu.org/software/social/',
  38. 'description' =>
  39. // TRANS: Plugin description.
  40. _m('Opportunistic queue manager plugin for background processing.'));
  41. return true;
  42. }
  43. }