3 use Drush\Log\LogLevel;
6 * Implements hook_drush_help().
8 function queue_drush_help($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.');
16 * Implements hook_drush_command().
18 function queue_drush_command() {
19 $items['queue-run'] = array(
20 'description' => 'Run a specific queue by name',
22 'queue_name' => 'The name of the queue to run, as defined in either hook_queue_info or hook_cron_queue_info.',
24 'required-arguments' => TRUE,
26 'time-limit' => 'The maximum number of seconds allowed to run the queue',
29 $items['queue-list'] = array(
30 'description' => 'Returns a list of all defined queues',
31 'outputformat' => array(
33 'pipe-format' => 'csv',
34 'field-labels' => array(
39 'ini-item' => 'items',
40 'table-metadata' => array(
41 'key-value-item' => 'items',
43 'output-data-type' => 'format-table',
51 * Validation callback for drush queue-run.
53 function drush_queue_run_validate($queue_name) {
55 $queue = drush_queue_get_class();
56 $queue->getInfo($queue_name);
58 catch (\Drush\Queue\QueueException $exception) {
59 return drush_set_error('DRUSH_QUEUE_RUN_VALIDATION_ERROR', $exception->getMessage());
64 * Return the appropriate queue class.
66 function drush_queue_get_class() {
67 return drush_get_class('Drush\Queue\Queue');
71 * Command callback for drush queue-run.
73 * Queue runner that is compatible with queues declared using both
74 * hook_queue_info() and hook_cron_queue_info().
77 * Arbitrary string. The name of the queue to work with.
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);
89 * Command callback for drush queue-list.
91 function drush_queue_list() {
92 $queue = drush_queue_get_class();
93 return $queue->listQueues();