You are here

public function SerialLauncher::runThread in Ultimate Cron 8.2

1 call to SerialLauncher::runThread()
SerialLauncher::launchJobs in src/Plugin/ultimate_cron/Launcher/SerialLauncher.php
Default implementation of jobs launcher.

File

src/Plugin/ultimate_cron/Launcher/SerialLauncher.php, line 316

Class

SerialLauncher
Ultimate Cron launcher plugin class.

Namespace

Drupal\ultimate_cron\Plugin\ultimate_cron\Launcher

Code

public function runThread($lock_id, $thread, $jobs) {
  $lock = \Drupal::service('ultimate_cron.lock');
  $lock_name = 'ultimate_cron_serial_launcher_' . $thread;
  foreach ($jobs as $job) {
    $configuration = $job
      ->getConfiguration('launcher');
    $configuration['launcher'] += array(
      'thread' => 'any',
    );
    switch ($configuration['launcher']['thread']) {
      case 'any':
        $configuration['launcher']['thread'] = $thread;
        break;
      case 'fixed':
        $configuration['launcher']['thread'] = $job
          ->getUniqueID() % $configuration['launcher']['max_threads'] + 1;
        break;
    }
    if ((!self::getGlobalOption('thread') || $configuration['launcher']['thread'] == $thread) && $job
      ->isScheduled()) {
      $this
        ->launch($job);

      // Be friendly, and check if someone else has taken the lock.
      // If they have, bail out, since someone else is now handling
      // this thread.
      if ($current_lock_id = $lock
        ->isLocked($lock_name)) {
        if ($current_lock_id !== $lock_id) {
          return;
        }
      }
      else {

        // If lock is free, then take the lock again.
        $lock_id = $lock
          ->lock($lock_name);
        if (!$lock_id) {

          // Race-condition, someone beat us to it.
          return;
        }
      }
    }
  }
}