You are here

protected function Cron::invokeCronHandlers in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()
  2. 10 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()

Invokes any cron handlers implementing hook_cron.

1 call to Cron::invokeCronHandlers()
Cron::run in core/lib/Drupal/Core/Cron.php
Executes a cron run.

File

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

Class

Cron
The Drupal core Cron service.

Namespace

Drupal\Core

Code

protected function invokeCronHandlers() {
  $module_previous = '';

  // If detailed logging isn't enabled, don't log individual execution times.
  $time_logging_enabled = \Drupal::config('system.cron')
    ->get('logging');
  $logger = $time_logging_enabled ? $this->logger : new NullLogger();

  // Iterate through the modules calling their cron handlers (if any):
  foreach ($this->moduleHandler
    ->getImplementations('cron') as $module) {
    if (!$module_previous) {
      $logger
        ->info('Starting execution of @module_cron().', [
        '@module' => $module,
      ]);
    }
    else {
      $logger
        ->info('Starting execution of @module_cron(), execution of @module_previous_cron() took @time.', [
        '@module' => $module,
        '@module_previous' => $module_previous,
        '@time' => Timer::read('cron_' . $module_previous) . 'ms',
      ]);
    }
    Timer::start('cron_' . $module);

    // Do not let an exception thrown by one module disturb another.
    try {
      $this->moduleHandler
        ->invoke($module, 'cron');
    } catch (\Exception $e) {
      watchdog_exception('cron', $e);
    }
    Timer::stop('cron_' . $module);
    $module_previous = $module;
  }
  if ($module_previous) {
    $logger
      ->info('Execution of @module_previous_cron() took @time.', [
      '@module_previous' => $module_previous,
      '@time' => Timer::read('cron_' . $module_previous) . 'ms',
    ]);
  }
}