public function UltimateCronCommands::unlock in Ultimate Cron 8.2
Unlock cron job.
@command cron:unlock
@option all Enabled all jobs @usage drush cron-unlock node_cron Unlock the node_cron job @aliases cru cron-unlock
Parameters
string $name: Job to unlock.
array $options: Options array.
File
- src/
Commands/ UltimateCronCommands.php, line 385
Class
- UltimateCronCommands
- Class UltimateCronCommands.
Namespace
Drupal\ultimate_cron\CommandsCode
public function unlock($name, array $options = [
'all' => NULL,
]) {
if (!$name) {
if (!$options['all']) {
throw new \Exception(dt('No job specified?'));
}
/** @var \Drupal\ultimate_cron\Entity\CronJob $job */
foreach (CronJob::loadMultiple() as $job) {
if ($job
->isLocked()) {
$job
->unlock();
}
}
return;
}
/** @var \Drupal\ultimate_cron\Entity\CronJob $job */
$job = CronJob::load($name);
if (!$job) {
throw new \Exception(dt('@name not found', [
'@name' => $name,
]));
}
$lock_id = $job
->isLocked();
if (!$lock_id) {
throw new \Exception(dt('@name is not running', [
'@name' => $name,
]));
}
// Unlock the process.
if ($job
->unlock($lock_id, TRUE)) {
$log_entry = $job
->resumeLog($lock_id);
global $user;
$this->logger
->warning('@name manually unlocked by user @username (@uid)', [
'@name' => $job
->id(),
'@username' => $user
->getDisplayName(),
'@uid' => $user
->id(),
]);
$log_entry
->finish();
$this->output
->writeln(dt('Cron job @name unlocked', [
'@name' => $name,
]));
}
else {
throw new \Exception(dt('Could not unlock cron job @name', [
'@name' => $name,
]));
}
}