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