In background batch, it doesn't redirect to the http://example.com/batch?op=start&id=xxx page to view the progress, because the invoking for $redirect_callback is commented in background_batch.module.

Code snippet:

function background_batch_process_batch($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto') {
  $batch =& batch_get();

  drupal_theme_initialize();

  if (isset($batch)) {
    // Add process information
    $process_info = array(
      'current_set' => 0,
      'progressive' => TRUE,
      'url' => $url,
      'url_options' => array(),
      'source_url' => $_GET['q'],
      'redirect' => $redirect,
      'theme' => $GLOBALS['theme_key'],
      'redirect_callback' => $redirect_callback,
    );

    // ...Ignore...

    $batch += $process_info;
    // Redirect for processing.
    $function = $batch['redirect_callback'];
    if (function_exists($function)) {
      // $function($batch['url'], array('query' => array('op' => 'start', 'id' => $batch['id'])));
    }
  }
  background_process_start('_background_batch_process_callback', $batch);
}

I remove the comment in this line, $function($batch['url'], array('query' => array('op' => 'start', 'id' => $batch['id'])));. After calling background_batch_process_batch(), a user will be redirected to the http://example.com/batch?op=start&id=xxx and view the progress percentage. However, once the background batch process completes, the row of bid is deleted in batch table in database. It results that the pooling for progress gets 404 Not Found response and a user also sees an error message.

The error message:

An AJAX HTTP error occurred. HTTP Result Code: 404 Debugging information follows. Path: /batch?id=xxx&op=do StatusText: Not Found ResponseText: Page not found ...

Should it be saved the batch status in database for avoiding to the missing batch id?

Comments

johnhuang0808 created an issue. See original summary.

johnhuang0808’s picture

Title: Batch progress batch » Background batch progress page
johnhuang0808’s picture

Status: Active » Closed (works as designed)
Related issues: +#1878764: Finished function not firing

The cause of the issue is applying the the patch in the Finished function not firing issue. The patch invokes _batch_finished() once the percentage is equal or larger 100. Hence, the bid (aka. batch id) of the row in batch table is deleted before progress in JavaScript gets the percentage by bid.

On the other hand, I also observed that sometimes the progress of the batch may be not 1 in progress table even the background batch completed. The patch in Progress table is not update even progress is 100% completed issue works for me.

BTW, should the line of $function($batch['url'], array('query' => array('op' => 'start', 'id' => $batch['id']))); be removed the comment in next release?

GuyPaddock’s picture

Category: Feature request » Bug report
Status: Closed (works as designed) » Active

This is still an issue.