You are here

public function EntityShareAsyncWorker::processItem in Entity Share 8.3

Same name and namespace in other branches
  1. 8.2 modules/entity_share_async/src/Plugin/QueueWorker/EntityShareAsyncWorker.php \Drupal\entity_share_async\Plugin\QueueWorker\EntityShareAsyncWorker::processItem()

Works on a single queue item.

Parameters

mixed $data: The data that was passed to \Drupal\Core\Queue\QueueInterface::createItem() when the item was queued.

Throws

\Drupal\Core\Queue\RequeueException Processing is not yet finished. This will allow another process to claim the item immediately.

\Exception A QueueWorker plugin may throw an exception to indicate there was a problem. The cron process will log the exception, and leave the item in the queue to be processed again later.

\Drupal\Core\Queue\SuspendQueueException More specifically, a SuspendQueueException should be thrown when a QueueWorker plugin is aware that the problem will affect all subsequent workers of its queue. For example, a callback that makes HTTP requests may find that the remote server is not responding. The cron process will behave as with a normal Exception, and in addition will not attempt to process further items from the current item's queue during the current cron run.

Overrides QueueWorkerInterface::processItem

See also

\Drupal\Core\Cron::processQueues()

File

modules/entity_share_async/src/Plugin/QueueWorker/EntityShareAsyncWorker.php, line 82

Class

EntityShareAsyncWorker
Asynchronous import queue worker.

Namespace

Drupal\entity_share_async\Plugin\QueueWorker

Code

public function processItem($item) {
  $async_states = $this->stateStorage
    ->get(QueueHelperInterface::STATE_ID, []);

  // Import the entity.
  $import_context = new ImportContext($item['remote_id'], $item['channel_id'], $item['import_config_id']);
  $ids = $this->importService
    ->importEntities($import_context, [
    $item['uuid'],
  ], FALSE);
  if (empty($ids)) {
    $this->logger
      ->warning("Cannot synchronize item @uuid from channel @channel_id of remote @remote_id with the import config @import_config_id", [
      '@uuid' => $item['uuid'],
      '@channel_id' => $item['channel_id'],
      '@remote_id' => $item['remote_id'],
      '@import_config_id' => $item['import_config_id'],
    ]);
  }
  if (isset($async_states[$item['remote_id']][$item['channel_id']][$item['uuid']])) {
    unset($async_states[$item['remote_id']][$item['channel_id']][$item['uuid']]);
  }

  // Update states.
  $this->stateStorage
    ->set(QueueHelperInterface::STATE_ID, $async_states);
}