BUGFIX: Reboot jobs should not exit the whole script
This commit is contained in:
parent
6333f20a5b
commit
c825dd9b7f
|
@ -49,6 +49,7 @@ class DaemonCommand extends Command
|
|||
$jobsToRun = $jobRepo->getJobsDue();
|
||||
if(!empty($jobsToRun)) {
|
||||
foreach($jobsToRun as $job) {
|
||||
if($jobRepo->getTempVar($job['id'], 'consolerun')) continue;
|
||||
$jobRepo->setJobRunning($job['id'], true);
|
||||
$output->writeln('Running Job ' . $job['id']);
|
||||
declare(ticks = 1);
|
||||
|
|
|
@ -35,8 +35,20 @@ class RunCommand extends Command
|
|||
$jobRepo = new Job($this->kernel->getDbCon());
|
||||
$jobId = (int)$input->getArgument('jobid');
|
||||
$jobRepo->setJobRunning($jobId, true);
|
||||
$jobRepo->setTempVar($jobId, 'consolerun', true);
|
||||
$result = $jobRepo->runNow($jobId, true);
|
||||
$job = $jobRepo->getJob($jobId);
|
||||
if($job['data']['crontype'] == 'reboot') {
|
||||
$sleeping = true;
|
||||
while($sleeping) {
|
||||
$job = $jobRepo->getJob($jobId);
|
||||
if(time() >= $job['running']) $sleeping = false;
|
||||
sleep(1);
|
||||
}
|
||||
$result = $jobRepo->runNow($jobId, true);
|
||||
}
|
||||
$jobRepo->setJobRunning($jobId, false);
|
||||
$jobRepo->setTempVar($jobId, 'consolerun', false);
|
||||
$output->write($result['output']);
|
||||
if($result['success']) {
|
||||
$output->writeln('Job succeeded with in ' . number_format($result['runtime'], 3) . 'secs exitcode ' . $result['exitcode']);
|
||||
|
|
|
@ -204,11 +204,12 @@ class Job extends Repository
|
|||
} elseif($job['data']['hosttype'] == 'local') {
|
||||
$this->runLocalCommand($job['data']['reboot-command']);
|
||||
}
|
||||
exit;
|
||||
|
||||
return ['status' => 'deferred'];
|
||||
|
||||
} elseif($job['running'] != 0) {
|
||||
if($job['running'] > time()) {
|
||||
exit;
|
||||
return ['status' => 'deferred'];
|
||||
}
|
||||
$starttime = (float)$this->getTempVar($job['id'], 'starttime');
|
||||
$this->deleteTempVar($job['id'], 'starttime');
|
||||
|
@ -241,9 +242,9 @@ class Job extends Repository
|
|||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id AND running IN (0,1,2)";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job['id'], ':status' => 2]);
|
||||
return ['success' => true, 'status' => 'deferred', 'title' => 'Cronjob has been scheduled', 'message' => 'Job was scheduled to be run. You will find the output soon in the job details'];
|
||||
} else {
|
||||
$output = $this->runJob($job['id'], true);
|
||||
if(!(isset($output['status']) && $output['status'] == 'deferred'))
|
||||
return [
|
||||
'status' => 'ran',
|
||||
'output' => ($console) ? $output['output'] : htmlentities($output['output']),
|
||||
|
@ -253,7 +254,7 @@ class Job extends Repository
|
|||
'success' => !str_contains($output['flags'], Run::FAILED)
|
||||
];
|
||||
}
|
||||
|
||||
return ['success' => true, 'status' => 'deferred', 'title' => 'Cronjob has been scheduled', 'message' => 'Job was scheduled to be run. You will find the output soon in the job details'];
|
||||
}
|
||||
|
||||
private function prepareDockerCommand(string $command, string $service, string|NULL $user): string
|
||||
|
@ -274,6 +275,7 @@ class Job extends Repository
|
|||
$result = $this->runCommandJob($job);
|
||||
} elseif ($job['data']['crontype'] == 'reboot') {
|
||||
$result = $this->runRebootJob($job, $starttime, $manual);
|
||||
if(isset($result['status']) && $result['status'] == 'deferred') return $result;
|
||||
}
|
||||
$endtime = microtime(true);
|
||||
$runtime = $endtime - $starttime;
|
||||
|
|
Loading…
Reference in New Issue