BUGFIX: guzzle does not only give request exceptions

This commit is contained in:
Jeroen De Meerleer 2021-10-18 15:17:36 +02:00
parent 1dc11efb6c
commit 5c3da88979
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 6 additions and 5 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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;