You are here

public function UltimateCron::run in Ultimate Cron 8.2

Same name in this branch
  1. 8.2 src/UltimateCron.php \Drupal\ultimate_cron\UltimateCron::run()
  2. 8.2 src/ProxyClass/UltimateCron.php \Drupal\ultimate_cron\ProxyClass\UltimateCron::run()

Executes a cron run.

Do not call this function from a test. Use $this->cronRun() instead.

Return value

bool TRUE upon success, FALSE otherwise.

Overrides Cron::run

File

src/UltimateCron.php, line 39

Class

UltimateCron
The Ultimate Cron service.

Namespace

Drupal\ultimate_cron

Code

public function run() {

  // Load the cron jobs in the right order.
  $job_ids = \Drupal::entityQuery('ultimate_cron_job')
    ->condition('status', TRUE)
    ->sort('weight', 'ASC')
    ->execute();
  $launcher_jobs = array();
  foreach (CronJob::loadMultiple($job_ids) as $job) {

    /* @var \Drupal\Core\Plugin\DefaultPluginManager $manager */
    $manager = \Drupal::service('plugin.manager.ultimate_cron.' . 'launcher');
    $launcher = $manager
      ->createInstance($job
      ->getLauncherId());
    $launcher_definition = $launcher
      ->getPluginDefinition();
    if (!isset($launchers) || in_array($launcher
      ->getPluginId(), $launchers)) {
      $launcher_jobs[$launcher_definition['id']]['launcher'] = $launcher;
      $launcher_jobs[$launcher_definition['id']]['sort'] = array(
        $launcher_definition['weight'],
      );
      $launcher_jobs[$launcher_definition['id']]['jobs'][$job
        ->id()] = $job;
      $launcher_jobs[$launcher_definition['id']]['jobs'][$job
        ->id()]->sort = array(
        $job
          ->loadLatestLogEntry()->start_time,
      );
    }
  }
  foreach ($launcher_jobs as $name => $launcher_job) {
    $launcher_job['launcher']
      ->launchJobs($launcher_job['jobs']);
  }

  // Run standard queue processing if our own handling is disabled.
  if (!$this->configFactory
    ->get('ultimate_cron.settings')
    ->get('queue.enabled')) {
    $this
      ->processQueues();
  }
  $this
    ->setCronLastTime();
  return TRUE;
}