OpportunisticQMPlugin.php 1.5 KB

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