public static function ContentHubImportQueue::batchProcess in Acquia Content Hub 8
Process the batch.
The batch worker will run through the queued items and process them according to their queue method.
Parameters
\Drupal\Core\Config\ImmutableConfig $config: The import configuration.
mixed $context: The batch context.
File
- src/
Controller/ ContentHubImportQueue.php, line 94
Class
- ContentHubImportQueue
- Implements an Import Queue for entities.
Namespace
Drupal\acquia_contenthub\ControllerCode
public static function batchProcess(ImmutableConfig $config, &$context) {
/** @var \Drupal\Core\Queue\QueueFactory $queue_factory */
$queue_factory = \Drupal::service('queue');
/** @var \Drupal\Core\Queue\QueueWorkerManagerInterface $queue_manager */
$queue_manager = \Drupal::service('plugin.manager.queue_worker');
$queue = $queue_factory
->get('acquia_contenthub_import_queue');
$worker = $queue_manager
->createInstance('acquia_contenthub_import_queue');
$queue_batch_size = $config
->get('import_queue_batch_size');
$batch_size = $queue_batch_size === 'all' || $queue
->numberOfItems() < $queue_batch_size ? $queue
->numberOfItems() : $queue_batch_size;
for ($i = 0; $i < $batch_size; $i++) {
if ($item = $queue
->claimItem()) {
try {
$worker
->processItem($item->data);
$queue
->deleteItem($item);
} catch (SuspendQueueException $exception) {
$context['errors'][] = $exception
->getMessage();
$context['success'] = FALSE;
$queue
->releaseItem($item);
break;
} catch (EntityStorageException $exception) {
$context['errors'][] = $exception
->getMessage();
$context['success'] = FALSE;
$queue
->releaseItem($item);
break;
}
}
}
}