You are here

protected function Cron::invokeCronHandlers in Drupal 8

Same name and namespace in other branches
  1. 9 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 210

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
        ->notice('Starting execution of @module_cron().', [
        '@module' => $module,
      ]);
    }
    else {
      $logger
        ->notice('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
      ->notice('Execution of @module_previous_cron() took @time.', [
      '@module_previous' => $module_previous,
      '@time' => Timer::read('cron_' . $module_previous) . 'ms',
    ]);
  }
}