You are here

class UltimateCron in Ultimate Cron 8.2

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

The Ultimate Cron service.

Hierarchy

Expanded class hierarchy of UltimateCron

File

src/UltimateCron.php, line 19

Namespace

Drupal\ultimate_cron
View source
class UltimateCron extends Cron {

  /**
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Sets the config factory for ultimate cron service.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function setConfigFactory(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Cron::$accountSwitcher protected property The account switcher service.
Cron::$lock protected property The lock service.
Cron::$logger protected property A logger instance.
Cron::$moduleHandler protected property The module handler service.
Cron::$queueFactory protected property The queue service.
Cron::$queueManager protected property The queue plugin manager.
Cron::$state protected property The state service.
Cron::$time protected property The time service.
Cron::invokeCronHandlers protected function Invokes any cron handlers implementing hook_cron.
Cron::processQueues protected function Processes cron queues.
Cron::setCronLastTime protected function Records and logs the request time for this cron invocation.
Cron::__construct public function Constructs a cron object.
UltimateCron::$configFactory protected property
UltimateCron::run public function Executes a cron run. Overrides Cron::run
UltimateCron::setConfigFactory public function Sets the config factory for ultimate cron service.