function ReportWorkerBase::reportWork

Same name in other branches
  1. 3.x modules/cron_example/src/Plugin/QueueWorker/ReportWorkerBase.php \Drupal\cron_example\Plugin\QueueWorker\ReportWorkerBase::reportWork()
  2. 8.x-1.x 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 modules/cron_example/src/Plugin/QueueWorker/ReportWorkerOne.php
ReportWorkerTwo::processItem in modules/cron_example/src/Plugin/QueueWorker/ReportWorkerTwo.php

File

modules/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),
    ]);
}