function Cron::invokeCronHandlers

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()
  2. 10 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()
  3. 11.x 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 225

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):
    $this->moduleHandler
        ->invokeAllWith('cron', function (callable $hook, string $module) use (&$module_previous, $logger) {
        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 {
            $hook();
        } 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',
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.