Trigger a batch process via a rest endpoint and check on progress

by Chris   Last Updated February 11, 2019 09:07 AM

I'm looking to see if it's possible to trigger and monitor a batch process via a REST endpoint (or similar) in Drupal 8. This is for a headless Drupal site.

Triggering is fine I suppose, I can create the endpoint and use the batch api as normal, but how would I keep the batch running, monitor the progress, and resume if necessary?

I have found the function batch_do, but I'm unsure how it picks up the batch id etc.

 * Does one execution pass with JavaScript and returns progress to the browser.
 * @see _batch_progress_page_js()
 * @see _batch_process()
function _batch_do() {
  // Perform actual processing.
  list($percentage, $message, $label) = _batch_process();

  return new JsonResponse(['status' => TRUE, 'percentage' => $percentage, 'message' => $message, 'label' => $label]);
Tags : 8 batch-api

Related Questions

Batch API solutions

Updated June 04, 2017 19:07 PM

How to pass data between operations of a single Batch?

Updated September 13, 2017 17:07 PM