runqueue.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) { exit(1); }
  20. class RunqueueAction extends Action
  21. {
  22. protected $qm = null;
  23. protected function prepare(array $args = [])
  24. {
  25. parent::prepare($args);
  26. $args = [];
  27. if ($this->arg('qmkey') !== null) {
  28. $args['qmkey'] = $this->arg('qmkey');
  29. }
  30. try {
  31. $this->qm = new OpportunisticQueueManager($args);
  32. } catch (RunQueueBadKeyException $e) {
  33. return false;
  34. }
  35. header('Content-type: text/plain; charset=utf-8');
  36. return true;
  37. }
  38. protected function handle() {
  39. // We don't need any of the parent functionality from parent::handle() here.
  40. // runQueue is a loop that works until limits have passed or there is no more work
  41. if ($this->qm->runQueue() === true) {
  42. // We don't have any more work
  43. $this->text('0');
  44. } else {
  45. // There were still items left in queue when we aborted
  46. $this->text('1');
  47. }
  48. }
  49. }