function _drush_batch_worker

8.0.x batch_6.inc _drush_batch_worker()
8.0.x batch.inc _drush_batch_worker()
6.x batch_6.inc _drush_batch_worker()
6.x batch.inc _drush_batch_worker()
7.x batch_6.inc _drush_batch_worker()
7.x batch.inc _drush_batch_worker()
3.x batch_6.inc _drush_batch_worker()
3.x batch_7.inc _drush_batch_worker()
4.x batch_6.inc _drush_batch_worker()
4.x batch.inc _drush_batch_worker()
5.x batch_6.inc _drush_batch_worker()
5.x batch.inc _drush_batch_worker()
master batch.inc _drush_batch_worker()

Process batch operations

Using the current $batch process each of the operations until the batch has been completed or half of the available memory for the process has been reached.

2 calls to _drush_batch_worker()
_drush_batch_command in commands/core/drupal/batch_6.inc
Initialize the batch command and call the worker function.
_drush_batch_command in commands/core/drupal/batch.inc
Initialize the batch command and call the worker function.

File

commands/core/drupal/batch_6.inc, line 81
Drupal 6 engine for the Batch API

Code

function _drush_batch_worker() {
  $batch = &batch_get();
  $current_set = &_batch_current_set();
  $set_changed = TRUE;

  timer_start('batch_processing');

  while (!$current_set['success']) {
    // If this is the first time we iterate this batch set in the current
    // request, we check if it requires an additional file for functions
    // definitions.
    if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) {
      include_once ($current_set['file']);
    }

    $finished = 1;
    $task_message = '';
    if ((list($function, $args) = reset($current_set['operations'])) && function_exists($function)) {
      // Build the 'context' array, execute the function call,
      // and retrieve the user message.
      $batch_context = array(
        'sandbox' => &$current_set['sandbox'],
        'results' => &$current_set['results'],
        'finished' => &$finished,
        'message' => &$task_message,
      );
      // Magic wrap to catch changes to 'message' key.
      $batch_context = new DrushBatchContext($batch_context);
      // Process the current operation.
      call_user_func_array($function, array_merge($args, array(&$batch_context)));
      $finished = $batch_context['finished'];
    }

    if ($finished >= 1) {
      // Make sure this step isn't counted double when computing $current.
      $finished = 0;
      // Remove the operation and clear the sandbox.
      array_shift($current_set['operations']);
      $current_set['sandbox'] = array();
    }

    // If the batch set is completed, browse through the remaining sets,
    // executing 'control sets' (stored form submit handlers) along the way -
    // this might in turn insert new batch sets.
    // Stop when we find a set that actually has operations.
    $set_changed = FALSE;
    $old_set = $current_set;
    while (empty($current_set['operations']) && ($current_set['success'] = TRUE) && _batch_next_set()) {
      $current_set = &_batch_current_set();
      $set_changed = TRUE;
    }
    // At this point, either $current_set is a 'real' batch set (has operations),
    // or all sets have been completed.


    // TODO - replace with memory check!
    // If we're in progressive mode, stop after 1 second.
    if ((memory_get_usage() * 2) >= drush_memory_limit()) {
      drush_log(dt("Batch process has consumed in excess of 50% of available memory. Starting new thread"), "batch");
      break;
    }
  }

  // Gather progress information.

  // Reporting 100% progress will cause the whole batch to be considered
  // processed. If processing was paused right after moving to a new set,
  // we have to use the info from the new (unprocessed) one.
  if ($set_changed && isset($current_set['operations'])) {
    // Processing will continue with a fresh batch set.
    $remaining = count($current_set['operations']);
    $total = $current_set['total'];
    $task_message = '';
  }
  else {
    $remaining = count($old_set['operations']);
    $total = $old_set['total'];
  }

  $current = $total - $remaining + $finished;
  $percentage = $total ? floor($current / $total * 100) : 100;

  return ($percentage == 100);
}