You are here

class UltimateCronSignal in Ultimate Cron 7.2

Class for handling Ultimate Cron signals.

Hierarchy

Expanded class hierarchy of UltimateCronSignal

File

./ultimate_cron.signal.inc, line 10
File containing functions for Ultimate Cron signal handling.

View source
class UltimateCronSignal {

  /**
   * Get a signal without claiming it.
   *
   * @param string $name
   *   The name of the job.
   * @param string $signal
   *   The name of the signal.
   *
   * @return string
   *   The signal if any.
   */
  public static function peek($name, $signal) {
    $target = _ultimate_cron_get_transactional_safe_connection();
    return db_select('ultimate_cron_signal', 's', array(
      'target' => $target,
    ))
      ->fields('s', array(
      'job_name',
    ))
      ->condition('job_name', $name)
      ->condition('signal_name', $signal)
      ->condition('claimed', 0)
      ->execute()
      ->fetchField();
  }

  /**
   * Get and claim signal.
   *
   * @param string $name
   *   The name of the job.
   * @param string $signal
   *   The name of the signal.
   *
   * @return string
   *   The signal if any. If a signal is found, it is "claimed" and therefore
   *   cannot be claimed again.
   */
  public static function get($name, $signal) {
    $target = _ultimate_cron_get_transactional_safe_connection();
    $claimed = db_update('ultimate_cron_signal', array(
      'target' => $target,
    ))
      ->fields(array(
      'claimed' => 1,
    ))
      ->condition('job_name', $name)
      ->condition('signal_name', $signal)
      ->condition('claimed', 0)
      ->execute();
    if ($claimed) {
      db_delete('ultimate_cron_signal', array(
        'target' => $target,
      ))
        ->condition('job_name', $name)
        ->condition('signal_name', $signal)
        ->condition('claimed', 1)
        ->execute();
    }
    return $claimed;
  }

  /**
   * Set signal.
   *
   * @param string $name
   *   The name of the job.
   * @param string $signal
   *   The name of the signal.
   *
   * @return bool
   *   TRUE if the signal was set.
   */
  public static function set($name, $signal) {
    $target = _ultimate_cron_get_transactional_safe_connection();
    return db_merge('ultimate_cron_signal', array(
      'target' => $target,
    ))
      ->key(array(
      'job_name' => $name,
      'signal_name' => $signal,
    ))
      ->fields(array(
      'claimed' => 0,
    ))
      ->execute();
  }

  /**
   * Clear signal.
   *
   * @param string $name
   *   The name of the job.
   * @param string $signal
   *   The name of the signal.
   */
  public static function clear($name, $signal) {
    $target = _ultimate_cron_get_transactional_safe_connection();
    db_delete('ultimate_cron_signal', array(
      'target' => $target,
    ))
      ->condition('job_name', $name)
      ->condition('signal_name', $signal)
      ->execute();
  }

  /**
   * Clear signals.
   *
   * @param string $name
   *   The name of the job.
   */
  public static function flush($name) {
    $target = _ultimate_cron_get_transactional_safe_connection();
    db_delete('ultimate_cron_signal', array(
      'target' => $target,
    ))
      ->condition('job_name', $name)
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UltimateCronSignal::clear public static function Clear signal.
UltimateCronSignal::flush public static function Clear signals.
UltimateCronSignal::get public static function Get and claim signal.
UltimateCronSignal::peek public static function Get a signal without claiming it.
UltimateCronSignal::set public static function Set signal.