protected function Cron::invokeCronHandlers in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()
- 9 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::invokeCronHandlers()
Invokes any cron handlers implementing hook_cron.
1 call to Cron::invokeCronHandlers()
File
- core/
lib/ Drupal/ Core/ Cron.php, line 224
Class
- Cron
- The Drupal core Cron service.
Namespace
Drupal\CoreCode
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',
]);
}
}