You are here

public function UltimateCronSerialLauncher::launchJobs in Ultimate Cron 7.2

Launch manager.

Overrides UltimateCronLauncher::launchJobs

File

plugins/ultimate_cron/launcher/serial.class.php, line 287
Serial cron job launcher for Ultimate Cron.

Class

UltimateCronSerialLauncher
Ultimate Cron launcher plugin class.

Code

public function launchJobs($jobs) {
  $class = _ultimate_cron_get_class('lock');
  $settings = $this
    ->getDefaultSettings();

  // We only lock for 55 seconds at a time, to give room for other cron
  // runs.
  $lock_timeout = 55;
  if (!empty($_GET['thread'])) {
    self::setGlobalOption('thread', $_GET['thread']);
  }
  if ($thread = intval(self::getGlobalOption('thread'))) {
    if ($thread < 1 || $thread > $settings['max_threads']) {
      watchdog('serial_launcher', "Invalid thread available for starting launch thread", array(), WATCHDOG_ERROR);
      return;
    }
    $lock_name = 'ultimate_cron_serial_launcher_' . $thread;
    $lock_id = NULL;
    if (!$class::isLocked($lock_name)) {
      $lock_id = $class::lock($lock_name, $lock_timeout);
    }
    if (!$lock_id) {
      watchdog('serial_launcher', "Thread @thread is already running", array(
        '@thread' => $thread,
      ), WATCHDOG_WARNING);
    }
  }
  else {
    $timeout = 1;
    list($thread, $lock_id) = $this
      ->findFreeThread(TRUE, $lock_timeout, $timeout);
  }
  if (!$thread) {
    watchdog('serial_launcher', "No free threads available for launching jobs", array(), WATCHDOG_WARNING);
    return;
  }
  watchdog('serial_launcher', "Cron thread %thread started", array(
    '%thread' => $thread,
  ), WATCHDOG_DEBUG);
  $this
    ->runThread($lock_id, $thread, $jobs);
  $class::unlock($lock_id);
}