From 5c3da8897958ba81447abbc6f92dd3fa452fb806 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 18 Oct 2021 15:17:36 +0200 Subject: [PATCH] BUGFIX: guzzle does not only give request exceptions --- src/Command/DaemonCommand.php | 2 +- src/Command/RunCommand.php | 1 + src/Repository/Job.php | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Command/DaemonCommand.php b/src/Command/DaemonCommand.php index a1f937e..ce65911 100644 --- a/src/Command/DaemonCommand.php +++ b/src/Command/DaemonCommand.php @@ -54,7 +54,7 @@ class DaemonCommand extends Command $str = @file_get_contents('/proc/uptime'); $num = floatval($str); $rebootedself = ($num < $jobObj['data']['reboot-duration'] * 60); - $consolerun = $jobRepo->getTempVar($job['id'], 'consolerun'); + $consolerun = $jobRepo->getTempVar($job['id'], 'consolerun', false); if($consolerun && !$rebootedself) continue; } $jobRepo->setJobRunning($job['id'], true); diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 596a9b4..f22e3c9 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -30,6 +30,7 @@ class RunCommand extends Command ->setHelp('This command runs a single command') ->addArgument('jobid', InputArgument::REQUIRED, 'The id of the job to be run'); } + protected function execute(InputInterface $input, OutputInterface $output) { $jobRepo = new Job($this->kernel->getDbCon()); diff --git a/src/Repository/Job.php b/src/Repository/Job.php index d5a521a..4af3917 100644 --- a/src/Repository/Job.php +++ b/src/Repository/Job.php @@ -6,7 +6,7 @@ namespace JeroenED\Webcron\Repository; use DateTime; use GuzzleHttp\Client; -use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\GuzzleException; use JeroenED\Framework\Repository; use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Net\SSH2; @@ -114,13 +114,13 @@ class Job extends Repository return; } - public function getTempVar(int $job, string $name): mixed + public function getTempVar(int $job, string $name, mixed $default = NULL): mixed { $jobsSql = "SELECT data FROM job WHERE id = :id"; $jobsStmt = $this->dbcon->prepare($jobsSql); $result = $jobsStmt->executeQuery([':id' => $job])->fetchAssociative(); $result = json_decode($result['data'], true); - return $result['temp_vars'][$name]; + return $result['temp_vars'][$name] ?? $default; } private function runHttpJob(array $job): array @@ -142,7 +142,7 @@ class Job extends Repository $return['exitcode'] = $res->getStatusCode(); $return['output'] = $res->getBody(); $return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']); - } catch(RequestException $exception) { + } catch(GuzzleException $exception) { $return['exitcode'] = $exception->getCode(); $return['output'] = $exception->getMessage(); $return['failed'] = true;