BUGFIX: if job is running, don't run

This commit is contained in:
Jeroen De Meerleer 2021-07-15 13:22:52 +02:00
parent c825dd9b7f
commit f8c89230b7
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,11 @@ class RunCommand extends Command
{
$jobRepo = new Job($this->kernel->getDbCon());
$jobId = (int)$input->getArgument('jobid');
$jobRunning = $jobRepo->isLockedJob($jobId);
if($jobRunning) {
$output->writeln('Job is already running');
return Command::FAILURE;
}
$jobRepo->setJobRunning($jobId, true);
$jobRepo->setTempVar($jobId, 'consolerun', true);
$result = $jobRepo->runNow($jobId, true);

View File

@ -323,6 +323,14 @@ class Job extends Repository
return;
}
public function isLockedJob(int $id = 0): bool
{
$jobsSql = "SELECT id FROM job WHERE id = :id AND running != :status";
$params = [':status' => 0, ':id' => $id];
return count($this->dbcon->prepare($jobsSql)->executeQuery($params)->fetchAllAssociative()) > 0;
}
public function addJob(array $values)
{
if(empty($values['crontype']) ||