You are here

public function MessageQueueCreator::processItem in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  2. 8 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  3. 8.2 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  4. 8.3 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  5. 8.5 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  6. 8.6 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  7. 8.7 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  8. 8.8 modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  9. 10.3.x modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  10. 10.0.x modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  11. 10.1.x modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::processItem()
  12. 10.2.x modules/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php \Drupal\activity_logger\Plugin\QueueWorker\MessageQueueCreator::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/custom/activity_logger/src/Plugin/QueueWorker/MessageQueueCreator.php, line 23

Class

MessageQueueCreator
A report worker.

Namespace

Drupal\activity_logger\Plugin\QueueWorker

Code

public function processItem($data) {

  // First make sure it's an actual entity.
  if ($entity = Node::load($data['entity_id'])) {

    // Check if it's created more than 20 seconds ago.
    $timestamp = $entity
      ->getCreatedTime();

    // Current time.
    $now = time();
    $diff = abs($now - $timestamp);

    // Items must be at least 5 seconds old.
    if ($diff <= 5 && $now > $timestamp) {

      // Wait for 100 milliseconds.
      // We don't want to flood the DB with unprocessable queue items.
      usleep(100000);
      $queue = \Drupal::queue('activity_logger_message');
      $queue
        ->createItem($data);
    }
    else {
      $activity_logger_factory = \Drupal::service('plugin.manager.activity_action.processor');

      // Trigger the create action for enttites.
      $create_action = $activity_logger_factory
        ->createInstance('create_entitiy_action');
      $create_action
        ->createMessage($entity);
    }
  }
}