Log job requests
This commit is contained in:
@ -3,6 +3,7 @@ namespace Incoviba\Command;
|
|||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
|
use Psr\Http\Client\ClientExceptionInterface;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Console;
|
use Symfony\Component\Console;
|
||||||
@ -58,7 +59,12 @@ class Queue extends Command
|
|||||||
{
|
{
|
||||||
$uri = "/api/queue/run/{$job_id}";
|
$uri = "/api/queue/run/{$job_id}";
|
||||||
$output->writeln("GET {$uri}");
|
$output->writeln("GET {$uri}");
|
||||||
|
try {
|
||||||
$response = $this->client->get($uri);
|
$response = $this->client->get($uri);
|
||||||
|
} catch (ClientExceptionInterface $exception) {
|
||||||
|
$this->logger->error($exception->getMessage());
|
||||||
|
return Console\Command\Command::FAILURE;
|
||||||
|
}
|
||||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||||
|
|
||||||
return ((int) floor($response->getStatusCode() / 100) === 2) ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
|
return ((int) floor($response->getStatusCode() / 100) === 2) ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
|
||||||
|
@ -24,7 +24,9 @@ class Login
|
|||||||
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
|
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
|
||||||
]);
|
]);
|
||||||
} catch (ClientExceptionInterface $exception) {
|
} catch (ClientExceptionInterface $exception) {
|
||||||
$this->logger->error($exception);
|
$this->logger->error($exception, [
|
||||||
|
'username' => $this->username
|
||||||
|
]);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +48,11 @@ class Login
|
|||||||
file_put_contents($this->tokenFilename, $data['token']);
|
file_put_contents($this->tokenFilename, $data['token']);
|
||||||
return $data['token'];
|
return $data['token'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function retrieveToken(): string
|
public function retrieveToken(): string
|
||||||
{
|
{
|
||||||
if (!file_exists($this->tokenFilename)) {
|
if (!file_exists($this->tokenFilename)) {
|
||||||
@ -61,7 +68,9 @@ class Login
|
|||||||
'headers' => ['Authorization' => "Bearer {$token}"]
|
'headers' => ['Authorization' => "Bearer {$token}"]
|
||||||
]);
|
]);
|
||||||
} catch (ClientExceptionInterface $exception) {
|
} catch (ClientExceptionInterface $exception) {
|
||||||
$this->logger->error($exception);
|
$this->logger->error($exception, [
|
||||||
|
'token' => $token
|
||||||
|
]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $response->getStatusCode() === 200;
|
return $response->getStatusCode() === 200;
|
||||||
@ -69,18 +78,20 @@ class Login
|
|||||||
public function getKey(string $apiKey, string $separator = 'g'): string
|
public function getKey(string $apiKey, string $separator = 'g'): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$token = $this->retrieveToken();
|
$savedToken = $this->retrieveToken();
|
||||||
if (!$this->tryToken(implode('', [md5($apiKey), $separator, $token]))) {
|
$token = implode('', [md5($apiKey), $separator, $savedToken]);
|
||||||
|
if (!$this->tryToken($token)) {
|
||||||
throw new Exception('Token not valid');
|
throw new Exception('Token not valid');
|
||||||
}
|
}
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->logger->notice($exception);
|
$this->logger->notice($exception);
|
||||||
$token = $this->login();
|
$savedToken = $this->login();
|
||||||
if ($token === '') {
|
if ($savedToken === '') {
|
||||||
unlink($this->tokenFilename);
|
unlink($this->tokenFilename);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
$token = implode('', [md5($apiKey), $separator, $savedToken]);
|
||||||
}
|
}
|
||||||
return implode('', [md5($apiKey), $separator, $token]);
|
return $token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user