queue.drush.inc

  1. 8.0.x commands/core/queue.drush.inc
  2. 6.x commands/core/queue.drush.inc
  3. 7.x commands/core/queue.drush.inc
  4. 5.x commands/core/queue.drush.inc
  5. master commands/core/queue.drush.inc

Functions

Namesort descending Description
drush_queue_get_class Return the appropriate queue class.
drush_queue_list Command callback for drush queue-list.
drush_queue_run Command callback for drush queue-run.
drush_queue_run_validate Validation callback for drush queue-run.
queue_drush_command Implements hook_drush_command().
queue_drush_help Implements hook_drush_help().

File

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