class SignalCache in Ultimate Cron 8.2
Hierarchy
- class \Drupal\ultimate_cron\Signal\SignalCache implements SignalInterface
Expanded class hierarchy of SignalCache
1 string reference to 'SignalCache'
1 service uses SignalCache
File
- src/
Signal/ SignalCache.php, line 9
Namespace
Drupal\ultimate_cron\SignalView source
class SignalCache implements SignalInterface {
/**
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
public $cacheBackend;
/**
* @var \Drupal\Core\Lock\LockBackendInterface
*/
public $lockBackend;
public function __construct(CacheBackendInterface $cache_backend, LockBackendInterface $lock_backend) {
$this->cacheBackend = $cache_backend;
$this->lockBackend = $lock_backend;
}
/**
* Get a signal without claiming it.
*
* @param string $job_id
* The name of the job.
* @param string $signal
* The name of the signal.
*
* @return string
* The signal if any.
*/
public function peek($job_id, $signal) {
$cache = $this->cacheBackend
->get("signal-{$job_id}-{$signal}");
if ($cache) {
$flushed = $this->cacheBackend
->get("flushed-{$job_id}");
if (!$flushed || $cache->created > $flushed->created) {
return $cache->data;
}
}
return FALSE;
}
/**
* 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 function get($job_id, $signal) {
if ($this->lockBackend
->acquire("signal-{$job_id}-{$signal}")) {
$result = self::peek($job_id, $signal);
self::clear($job_id, $signal);
$this->lockBackend
->release("signal-{$job_id}-{$signal}");
return $result;
}
return FALSE;
}
/**
* Set signal.
*
* @param string $job_id
* The name of the job.
* @param string $signal
* The name of the signal.
*
* @return boolean
* TRUE if the signal was set.
*/
public function set($job_id, $signal) {
$this->cacheBackend
->set("signal-{$job_id}-{$signal}", TRUE);
}
/**
* Clear signal.
*
* @param string $job_id
* The name of the job.
* @param string $signal
* The name of the signal.
*/
public function clear($job_id, $signal) {
$this->cacheBackend
->delete("signal-{$job_id}-{$signal}");
}
/**
* Clear signals.
*
* @param string $job_id
* The name of the job.
*/
public function flush($job_id) {
$this->cacheBackend
->set("flushed-{$job_id}", microtime(TRUE));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SignalCache:: |
public | property | ||
SignalCache:: |
public | property | ||
SignalCache:: |
public | function |
Clear signal. Overrides SignalInterface:: |
|
SignalCache:: |
public | function |
Clear signals. Overrides SignalInterface:: |
|
SignalCache:: |
public | function |
Get and claim signal. Overrides SignalInterface:: |
|
SignalCache:: |
public | function |
Get a signal without claiming it. Overrides SignalInterface:: |
|
SignalCache:: |
public | function |
Set signal. Overrides SignalInterface:: |
|
SignalCache:: |
public | function |