You are here

public function UltimateCronSerialLauncher::launch in Ultimate Cron 7.2

Launcher.

Overrides UltimateCronLauncher::launch

File

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

Class

UltimateCronSerialLauncher
Ultimate Cron launcher plugin class.

Code

public function launch($job) {
  $lock_id = $job
    ->lock();
  if (!$lock_id) {
    return FALSE;
  }
  if ($this->currentThread) {
    $init_message = t('Launched in thread @current_thread', array(
      '@current_thread' => $this->currentThread,
    ));
  }
  else {
    $init_message = t('Launched manually');
  }
  $log_entry = $job
    ->startLog($lock_id, $init_message);
  drupal_set_message(t('@name: @init_message', array(
    '@name' => $job->name,
    '@init_message' => $init_message,
  )));
  $class = _ultimate_cron_get_class('lock');
  try {

    // Allocate time for the job's lock if necessary.
    $settings = $job
      ->getSettings($this->type);
    $lock_timeout = drupal_set_time_limit($settings['lock_timeout']);

    // Relock cron thread with proper timeout.
    if ($this->currentThreadLockId) {
      $class::reLock($this->currentThreadLockId, $settings['lock_timeout']);
    }

    // Run job.
    $job
      ->run();
  } catch (Throwable $e) {
    ultimate_cron_watchdog_throwable('serial_launcher', $e, 'Error executing %job: @error', array(
      '%job' => $job->name,
      '@error' => (string) $e,
    ), WATCHDOG_ERROR);
    $log_entry
      ->finish();
    $job
      ->unlock($lock_id);
    return FALSE;
  } catch (Exception $e) {
    watchdog_exception('serial_launcher', $e, 'Error executing %job: @error', array(
      '%job' => $job->name,
      '@error' => (string) $e,
    ), WATCHDOG_ERROR);
    $log_entry
      ->finish();
    $job
      ->unlock($lock_id);
    return FALSE;
  }
  $log_entry
    ->finish();
  $job
    ->unlock($lock_id);
  return TRUE;
}