OpportunisticQMPlugin.php 1.6 KB

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