You are here

protected function PullController::processQueue in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_pull/src/Controller/PullController.php \Drupal\salesforce_pull\Controller\PullController::processQueue()
  2. 5.0.x modules/salesforce_pull/src/Controller/PullController.php \Drupal\salesforce_pull\Controller\PullController::processQueue()

Helper method to process queue.

1 call to PullController::processQueue()
PullController::endpoint in modules/salesforce_pull/src/Controller/PullController.php
Page callback to process push queue for a given mapping.

File

modules/salesforce_pull/src/Controller/PullController.php, line 190

Class

PullController
Push controller.

Namespace

Drupal\salesforce_pull\Controller

Code

protected function processQueue() {
  $start = microtime(TRUE);
  $worker = $this->queueWorkerManager
    ->createInstance(QueueHandler::PULL_QUEUE_NAME);
  $end = time() + $this
    ->getTimeLimit();
  $queue = $this->queueService
    ->get(QueueHandler::PULL_QUEUE_NAME);
  $count = 0;
  while ((!$this
    ->getTimeLimit() || time() < $end) && ($item = $queue
    ->claimItem())) {
    try {
      $this->eventDispatcher
        ->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, 'Processing item @id from @name queue.', [
        '@name' => QueueHandler::PULL_QUEUE_NAME,
        '@id' => $item->item_id,
      ]));
      $worker
        ->processItem($item->data);
      $queue
        ->deleteItem($item);
      $count++;
    } catch (RequeueException $e) {

      // The worker requested the task to be immediately requeued.
      $queue
        ->releaseItem($item);
    } catch (SuspendQueueException $e) {

      // If the worker indicates there is a problem with the whole queue,
      // release the item.
      $queue
        ->releaseItem($item);
      throw new \Exception($e
        ->getMessage());
    }
  }
  $elapsed = microtime(TRUE) - $start;
  $this->eventDispatcher
    ->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, 'Processed @count items from the @name queue in @elapsed sec.', [
    '@count' => $count,
    '@name' => QueueHandler::PULL_QUEUE_NAME,
    '@elapsed' => round($elapsed, 2),
  ]));
}