batch.inc

  1. 8.0.x includes/batch.inc
  2. 8.0.x commands/core/drupal/batch.inc
  3. 6.x includes/batch.inc
  4. 6.x commands/core/drupal/batch.inc
  5. 7.x includes/batch.inc
  6. 7.x commands/core/drupal/batch.inc
  7. 3.x includes/batch.inc
  8. 4.x commands/core/drupal/batch.inc
  9. 4.x includes/batch.inc
  10. 5.x commands/core/drupal/batch.inc
  11. 5.x includes/batch.inc
  12. master commands/core/drupal/batch.inc
  13. master includes/batch.inc

Drush batch API.

This file contains a fork of the Drupal Batch API that has been drastically simplified and tailored to Drush's unique use case.

The existing API is very targeted towards environments that are web accessible, and would frequently attempt to redirect the user which would result in the drush process being completely destroyed with no hope of recovery.

While the original API does offer a 'non progressive' mode which simply calls each operation in sequence within the current process, in most implementations (Drupal 5 and 6), it would still attempt to redirect unless very specific conditions were met.

When operating in 'non progressive' mode, Drush would experience the problems that the API was written to solve in the first place, specifically that processes would exceed the available memory and exit with an error.

Each major release of Drupal has also had slightly different implementations of the batch API, and this provides a uniform interface to all of these implementations.

Functions

Namesort descending Description
drush_backend_batch_process Process a Drupal batch by spawning multiple Drush processes.
drush_batch_command Process sets from the specified batch.

File

includes/batch.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Drush batch API.
  5. *
  6. * This file contains a fork of the Drupal Batch API that has been drastically
  7. * simplified and tailored to Drush's unique use case.
  8. *
  9. * The existing API is very targeted towards environments that are web accessible,
  10. * and would frequently attempt to redirect the user which would result in the
  11. * drush process being completely destroyed with no hope of recovery.
  12. *
  13. * While the original API does offer a 'non progressive' mode which simply
  14. * calls each operation in sequence within the current process, in most
  15. * implementations (Drupal 5 and 6), it would still attempt to redirect
  16. * unless very specific conditions were met.
  17. *
  18. * When operating in 'non progressive' mode, Drush would experience the problems
  19. * that the API was written to solve in the first place, specifically that processes
  20. * would exceed the available memory and exit with an error.
  21. *
  22. * Each major release of Drupal has also had slightly different implementations
  23. * of the batch API, and this provides a uniform interface to all of these
  24. * implementations.
  25. *
  26. */
  27. /**
  28. * Process a Drupal batch by spawning multiple Drush processes.
  29. *
  30. * This function will include the correct batch engine for the current
  31. * major version of Drupal, and will make use of the drush_backend_invoke
  32. * system to spawn multiple worker threads to handle the processing of
  33. * the current batch, while keeping track of available memory.
  34. *
  35. * The batch system will process as many batch sets as possible until
  36. * the entire batch has been completed or half of the available memory
  37. * has been used.
  38. *
  39. * This function is a drop in replacement for the existing batch_process()
  40. * function of Drupal.
  41. *
  42. * @param command
  43. * The command to call for the back end process. By default this will be
  44. * the 'backend-process' command, but some commands such as updatedb will
  45. * have special initialization requirements, and will need to define and
  46. * use their own command.
  47. *
  48. */
  49. function drush_backend_batch_process($command = 'batch-process') {
  50. drush_include_engine('drupal', 'batch', drush_drupal_major_version());
  51. _drush_backend_batch_process($command);
  52. }
  53. /**
  54. * Process sets from the specified batch.
  55. *
  56. * This function is called by the worker process that is spawned by the
  57. * drush_backend_batch_process function.
  58. *
  59. * The command called needs to call this function after it's special bootstrap
  60. * requirements have been taken care of.
  61. */
  62. function drush_batch_command($id) {
  63. include_once('includes/batch.inc');
  64. drush_include_engine('drupal', 'batch', drush_drupal_major_version());
  65. _drush_batch_command($id);
  66. }