You are here

protected function ReportWorkerBase::reportWork in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/cron_example/src/Plugin/QueueWorker/ReportWorkerBase.php \Drupal\cron_example\Plugin\QueueWorker\ReportWorkerBase::reportWork()

Simple reporter log and display information about the queue.

Parameters

int $worker: Worker number.

object $item: The $item which was stored in the cron queue.

2 calls to ReportWorkerBase::reportWork()
ReportWorkerOne::processItem in cron_example/src/Plugin/QueueWorker/ReportWorkerOne.php
Works on a single queue item.
ReportWorkerTwo::processItem in cron_example/src/Plugin/QueueWorker/ReportWorkerTwo.php
Works on a single queue item.

File

cron_example/src/Plugin/QueueWorker/ReportWorkerBase.php, line 78

Class

ReportWorkerBase
Provides base functionality for the ReportWorkers.

Namespace

Drupal\cron_example\Plugin\QueueWorker

Code

protected function reportWork($worker, $item) {
  if ($this->state
    ->get('cron_example_show_status_message')) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Queue @worker worker processed item with sequence @sequence created at @time', [
      '@worker' => $worker,
      '@sequence' => $item->sequence,
      '@time' => date('c', $item->created),
    ]));
  }
  $this->logger
    ->get('cron_example')
    ->info('Queue @worker worker processed item with sequence @sequence created at @time', [
    '@worker' => $worker,
    '@sequence' => $item->sequence,
    '@time' => date('c', $item->created),
  ]);
}