You are here

public function SchedulerManager::runLightweightCron in Scheduler 2.x

Same name and namespace in other branches
  1. 8 src/SchedulerManager.php \Drupal\scheduler\SchedulerManager::runLightweightCron()

Run the lightweight cron.

The Scheduler part of the processing performed here is the same as in the normal Drupal cron run. The difference is that only scheduler_cron() is executed, no other modules hook_cron() functions are called.

This function is called from the external crontab job via url /scheduler/cron/{access key} or it can be run interactively from the Scheduler configuration page at /admin/config/content/scheduler/cron. It is also executed when running Scheduler Cron via drush.

Parameters

array $options: Options passed from drush command or admin form.

File

src/SchedulerManager.php, line 753

Class

SchedulerManager
Defines a scheduler manager.

Namespace

Drupal\scheduler

Code

public function runLightweightCron(array $options = []) {

  // When calling via drush the log messages can be avoided by using --nolog.
  $log = $this
    ->setting('log') && empty($options['nolog']);
  if ($log) {
    if (array_key_exists('nolog', $options)) {
      $trigger = 'drush command';
    }
    elseif (array_key_exists('admin_form', $options)) {
      $trigger = 'admin user form';
    }
    else {
      $trigger = 'url';
    }

    // This has to be 'notice' not 'info' so that drush can show the message.
    $this->logger
      ->notice('Lightweight cron run activated by @trigger.', [
      '@trigger' => $trigger,
    ]);
  }
  scheduler_cron();
  if (ob_get_level() > 0) {
    $handlers = ob_list_handlers();
    if (isset($handlers[0]) && $handlers[0] == 'default output handler') {
      ob_clean();
    }
  }
  if ($log) {
    $link = Link::fromTextAndUrl($this
      ->t('settings'), Url::fromRoute('scheduler.cron_form'));
    $this->logger
      ->notice('Lightweight cron run completed.', [
      'link' => $link
        ->toString(),
    ]);
  }
}