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_delete Command callback for drush queue-delete.
drush_queue_delete_validate Validation callback for drush queue-delete.
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. $items['queue-delete'] = array(
  44. 'description' => 'Delete all items in a specific queue',
  45. 'arguments' => array(
  46. 'queue_name' => 'The name of the queue to delete all items for, as defined in either hook_queue_info or hook_cron_queue_info.',
  47. ),
  48. 'required-arguments' => TRUE,
  49. );
  50. return $items;
  51. }
  52. /**
  53. * Validation callback for drush queue-run.
  54. */
  55. function drush_queue_run_validate($queue_name) {
  56. try {
  57. $queue = drush_queue_get_class();
  58. $queue->getInfo($queue_name);
  59. }
  60. catch (\Drush\Queue\QueueException $exception) {
  61. return drush_set_error('DRUSH_QUEUE_RUN_VALIDATION_ERROR', $exception->getMessage());
  62. }
  63. }
  64. /**
  65. * Return the appropriate queue class.
  66. */
  67. function drush_queue_get_class() {
  68. return drush_get_class('Drush\Queue\Queue');
  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. * Command callback for drush queue-list.
  89. */
  90. function drush_queue_list() {
  91. $queue = drush_queue_get_class();
  92. return $queue->listQueues();
  93. }
  94. /**
  95. * Validation callback for drush queue-delete.
  96. */
  97. function drush_queue_delete_validate($queue_name) {
  98. try {
  99. $queue = drush_queue_get_class();
  100. $queue->getInfo($queue_name);
  101. }
  102. catch (\Drush\Queue\QueueException $exception) {
  103. return drush_set_error('DRUSH_QUEUE_DELETE_VALIDATION_ERROR', $exception->getMessage());
  104. }
  105. }
  106. /**
  107. * Command callback for drush queue-delete.
  108. *
  109. * @param $queue_name
  110. * Arbitrary string. The name of the queue to work with.
  111. *
  112. * @return int
  113. */
  114. function drush_queue_delete($queue_name) {
  115. $drush_queue = drush_queue_get_class();
  116. $queue = $drush_queue->getQueue($queue_name);
  117. $queue->deleteQueue();
  118. drush_log(dt('All items in @name queue deleted.', array('@name' => $queue_name)), LogLevel::OK);
  119. }