yammerqueuehandler.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, 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('STATUSNET')) {
  20. exit(1);
  21. }
  22. /**
  23. * Queue handler for bumping the next chunk of Yammer import activity!
  24. *
  25. * @package YammerImportPlugin
  26. * @author Brion Vibber <brion@status.net>
  27. */
  28. class YammerQueueHandler extends QueueHandler
  29. {
  30. function transport()
  31. {
  32. return 'yammer';
  33. }
  34. function handle($notice)
  35. {
  36. $runner = YammerRunner::init();
  37. if ($runner->hasWork()) {
  38. try {
  39. if ($runner->iterate()) {
  40. if ($runner->hasWork()) {
  41. // More to do? Shove us back on the queue...
  42. $runner->startBackgroundImport();
  43. }
  44. }
  45. } catch (Exception $e) {
  46. try {
  47. $runner->recordError($e->getMessage());
  48. } catch (Exception $f) {
  49. common_log(LOG_ERR, "Error while recording error in Yammer background import: " . $e->getMessage() . " " . $f->getMessage());
  50. }
  51. }
  52. } else {
  53. // We're done!
  54. common_log(LOG_INFO, "Yammer import has no work to do at this time; discarding.");
  55. }
  56. return true;
  57. }
  58. }