I have the need to start several background batches, which need to run concurrently, at once.

I have the following code:

$batches = array(....);
foreach ($batches as $batch) {
  batch_set($batch);
  background_batch_process_batch();
}

Using the code above, all background batches are correctly registered - but they are run serially, not concurrently. Any idea's?

Comments

gielfeldt’s picture

Not sure, but I could image it's because of the global state of the $batch.

In any case, they will always be initialized sequentially. So if the batch job finishes quickly, it might look as if they're running sequentially.

You could try wrapping it, just to be sure:

<?php
function mymodule_perform_batch_operation($batch) {
  batch_set($batch);
  background_batch_process_batch();
}

$batches = array(....);
foreach ($batches as $batch) {
  background_process_start('mymodule_perform_batch_operation', $batch);
}

?>
rp7’s picture

Simply brilliant. Works like a charm. Thanks a lot!

gielfeldt’s picture

Status: Active » Fixed

No problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.