Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / queue.drush.inc
1 <?php
2
3 use Drush\Log\LogLevel;
4
5 /**
6  * Implements hook_drush_help().
7  */
8 function queue_drush_help($section) {
9   switch ($section) {
10     case 'drush:queue-run':
11       return dt('Run Drupal queue workers. As opposed to "drush cron" that can only be run one at a time on a single site, "drush queue-run" can be invoked as many times as the server load allows.');
12   }
13 }
14
15 /**
16  * Implements hook_drush_command().
17  */
18 function queue_drush_command() {
19   $items['queue-run'] = array(
20     'description' => 'Run a specific queue by name',
21     'arguments' => array(
22       'queue_name' => 'The name of the queue to run, as defined in either hook_queue_info or hook_cron_queue_info.',
23     ),
24     'required-arguments' => TRUE,
25     'options' => array(
26       'time-limit' => 'The maximum number of seconds allowed to run the queue',
27     ),
28   );
29   $items['queue-list'] = array(
30     'description' => 'Returns a list of all defined queues',
31     'outputformat' => array(
32       'default' => 'table',
33       'pipe-format' => 'csv',
34       'field-labels' => array(
35         'queue' => 'Queue',
36         'items' => 'Items',
37         'class' => 'Class',
38       ),
39       'ini-item' => 'items',
40       'table-metadata' => array(
41         'key-value-item' => 'items',
42       ),
43       'output-data-type' => 'format-table',
44     ),
45   );
46
47   return $items;
48 }
49
50 /**
51  * Validation callback for drush queue-run.
52  */
53 function drush_queue_run_validate($queue_name) {
54   try {
55     $queue = drush_queue_get_class();
56     $queue->getInfo($queue_name);
57   }
58   catch (\Drush\Queue\QueueException $exception) {
59     return drush_set_error('DRUSH_QUEUE_RUN_VALIDATION_ERROR', $exception->getMessage());
60   }
61 }
62
63 /**
64  * Return the appropriate queue class.
65  */
66 function drush_queue_get_class() {
67   return drush_get_class('Drush\Queue\Queue');
68 }
69
70 /**
71  * Command callback for drush queue-run.
72  *
73  * Queue runner that is compatible with queues declared using both
74  * hook_queue_info() and hook_cron_queue_info().
75  *
76  * @param $queue_name
77  *   Arbitrary string. The name of the queue to work with.
78  */
79 function drush_queue_run($queue_name) {
80   $queue = drush_queue_get_class();
81   $time_limit = (int) drush_get_option('time-limit');
82   $start = microtime(TRUE);
83   $count = $queue->run($queue_name, $time_limit);
84   $elapsed = microtime(TRUE) - $start;
85   drush_log(dt('Processed @count items from the @name queue in @elapsed sec.', array('@count' => $count, '@name' => $queue_name, '@elapsed' => round($elapsed, 2))), drush_get_error() ? LogLevel::WARNING : LogLevel::OK);
86 }
87
88 /**
89  * Command callback for drush queue-list.
90  */
91 function drush_queue_list() {
92   $queue = drush_queue_get_class();
93   return $queue->listQueues();
94 }
95