Queue7.php

  1. 8.0.x lib/Drush/Queue/Queue7.php
  2. 7.x lib/Drush/Queue/Queue7.php
  3. master lib/Drush/Queue/Queue7.php

Namespace

Drush\Queue

Classes

Namesort descending Description
Queue7

File

lib/Drush/Queue/Queue7.php
View source
  1. <?php
  2. namespace Drush\Queue;
  3. use Drush\Log\LogLevel;
  4. use DrupalQueue;
  5. class Queue7 extends QueueBase {
  6. /**
  7. * {@inheritdoc}
  8. */
  9. public function getQueues() {
  10. if (!isset(static::$queues)) {
  11. static::$queues = module_invoke_all('cron_queue_info');
  12. drupal_alter('cron_queue_info', static::$queues);
  13. // Merge in queues from modules that implement hook_queue_info.
  14. // Currently only defined by the queue_ui module.
  15. $info_queues = module_invoke_all('queue_info');
  16. foreach ($info_queues as $name => $queue) {
  17. static::$queues[$name]['worker callback'] = $queue['cron']['callback'];
  18. if (isset($queue['cron']['time'])) {
  19. static::$queues[$name]['time'] = $queue['cron']['time'];
  20. }
  21. }
  22. }
  23. return static::$queues;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. *
  28. * @return \DrupalQueueInterface
  29. */
  30. public function getQueue($name) {
  31. return DrupalQueue::get($name);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function run($name, $time_limit = 0) {
  37. $info = $this->getInfo($name);
  38. $function = $info['worker callback'];
  39. $end = time() + $time_limit;
  40. $queue = $this->getQueue($name);
  41. $count = 0;
  42. while ((!$time_limit || time() < $end) && ($item = $queue->claimItem())) {
  43. try {
  44. drush_log(dt('Processing item @id from @name queue.', array('@name' => $name, 'id' => $item->item_id)), LogLevel::INFO);
  45. $function($item->data);
  46. $queue->deleteItem($item);
  47. $count++;
  48. }
  49. catch (\Exception $e) {
  50. // In case of exception log it and leave the item in the queue
  51. // to be processed again later.
  52. drush_set_error('DRUSH_QUEUE_EXCEPTION', $e->getMessage());
  53. }
  54. }
  55. return $count;
  56. }
  57. }