function Cron::run

Same name in this branch
  1. 10 core/lib/Drupal/Core/ProxyClass/Cron.php \Drupal\Core\ProxyClass\Cron::run()
Same name in other branches
  1. 9 core/lib/Drupal/Core/ProxyClass/Cron.php \Drupal\Core\ProxyClass\Cron::run()
  2. 9 core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::run()
  3. 8.9.x core/lib/Drupal/Core/ProxyClass/Cron.php \Drupal\Core\ProxyClass\Cron::run()
  4. 8.9.x core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::run()
  5. 11.x core/lib/Drupal/Core/ProxyClass/Cron.php \Drupal\Core\ProxyClass\Cron::run()
  6. 11.x core/lib/Drupal/Core/Cron.php \Drupal\Core\Cron::run()

File

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

Class

Cron
The Drupal core Cron service.

Namespace

Drupal\Core

Code

public function run() {
    // Allow execution to continue even if the request gets cancelled.
    @ignore_user_abort(TRUE);
    // Force the current user to anonymous to ensure consistent permissions on
    // cron runs.
    $this->accountSwitcher
        ->switchTo(new AnonymousUserSession());
    // Try to allocate enough time to run all the hook_cron implementations.
    Environment::setTimeLimit(240);
    $return = FALSE;
    // Try to acquire cron lock.
    if (!$this->lock
        ->acquire('cron', 900.0)) {
        // Cron is still running normally.
        $this->logger
            ->warning('Attempting to re-run cron while it is already running.');
    }
    else {
        $this->invokeCronHandlers();
        // Process cron queues.
        $this->processQueues();
        $this->setCronLastTime();
        // Release cron lock.
        $this->lock
            ->release('cron');
        // Add watchdog message.
        $this->logger
            ->info('Cron run completed.');
        // Return TRUE so other functions can check if it did run successfully
        $return = TRUE;
    }
    // Restore the user.
    $this->accountSwitcher
        ->switchBack();
    return $return;
}

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