W3cubDocs

/Drupal 8

protected function Cron::processQueues

protected Cron::processQueues()

Processes cron queues.

File

core/lib/Drupal/Core/Cron.php, line 151

Class

Cron
The Drupal core Cron service.

Namespace

Drupal\Core

Code

protected function processQueues() {
  // Grab the defined cron queues.
  foreach ($this->queueManager->getDefinitions() as $queue_name => $info) {
    if (isset($info['cron'])) {
      // Make sure every queue exists. There is no harm in trying to recreate
      // an existing queue.
      $this->queueFactory->get($queue_name)->createQueue();

      $queue_worker = $this->queueManager->createInstance($queue_name);
      $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
      $queue = $this->queueFactory->get($queue_name);
      $lease_time = isset($info['cron']['time']) ? : NULL;
      while (time() < $end && ($item = $queue->claimItem($lease_time))) {
        try {
          $queue_worker->processItem($item->data);
          $queue->deleteItem($item);
        }
        catch (RequeueException $e) {
          // The worker requested the task be immediately requeued.
          $queue->releaseItem($item);
        }
        catch (SuspendQueueException $e) {
          // If the worker indicates there is a problem with the whole queue,
          // release the item and skip to the next queue.
          $queue->releaseItem($item);

          watchdog_exception('cron', $e);

          // Skip to the next queue.
          continue 2;
        }
        catch (\Exception $e) {
          // In case of any other kind of exception, log it and leave the item
          // in the queue to be processed again later.
          watchdog_exception('cron', $e);
        }
      }
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cron.php/function/Cron::processQueues/8.1.x