public function Lock::cleanup in Ultimate Cron 8.2
Cleanup expired locks.
Overrides LockInterface::cleanup
File
- src/
Lock/ Lock.php, line 212
Class
- Lock
- Class for handling lock functions.
Namespace
Drupal\ultimate_cron\LockCode
public function cleanup() {
$count = 0;
$class = \Drupal::entityTypeManager()
->getDefinition('ultimate_cron_job')
->getClass();
$now = microtime(TRUE);
$this->connection
->update('ultimate_cron_lock')
->expression('current', 'lid')
->condition('expire', $now, '<=')
->execute();
do {
$lids = $this->connection
->select('ultimate_cron_lock', 'l')
->fields('l', array(
'lid',
))
->where('l.current = l.lid')
->range(0, 100)
->execute()
->fetchCol();
if ($lids) {
$count += count($lids);
$this->connection
->delete('ultimate_cron_lock')
->condition('lid', $lids, 'IN')
->execute();
}
if ($job = $class::$currentJob) {
if ($job
->getSignal('kill')) {
\Drupal::logger('ultimate_cron')
->warning('kill signal recieved');
return;
}
}
} while ($lids);
if ($count) {
\Drupal::logger('ultimate_cron_lock')
->info('Cleaned up @count expired locks', [
'@count' => $count,
]);
}
}