FastCGI
This commit is contained in:
@ -7,8 +7,10 @@ use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console;
|
||||
use Incoviba\Service\FastCGI;
|
||||
use Incoviba\Service\Job;
|
||||
use Incoviba\Common\Alias\Command;
|
||||
use Incoviba\Exception\Client\FastCGI as FastCGIException;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'queue',
|
||||
@ -16,10 +18,11 @@ use Incoviba\Common\Alias\Command;
|
||||
)]
|
||||
class Queue extends Command
|
||||
{
|
||||
public function __construct(ClientInterface $client, LoggerInterface $logger,
|
||||
protected Job $jobService,
|
||||
public function __construct(ClientInterface $client, LoggerInterface $logger,
|
||||
protected Job $jobService,
|
||||
protected DateTimeZone $timezone,
|
||||
?string $name = null)
|
||||
protected FastCGI $fastcgi,
|
||||
?string $name = null)
|
||||
{
|
||||
parent::__construct($client, $logger, $name);
|
||||
}
|
||||
@ -55,20 +58,30 @@ class Queue extends Command
|
||||
$errors ++;
|
||||
}
|
||||
}
|
||||
$responses = $this->fastcgi->awaitResponses();
|
||||
foreach ($responses as $response) {
|
||||
if ((int) floor($response->getStatusCode() / 100) !== 2) {
|
||||
$this->logger->error("Error running job", [
|
||||
'status' => $response->getStatusCode(),
|
||||
'body' => $response->getBody()->getContents(),
|
||||
'headers' => $response->getHeaders(),
|
||||
]);
|
||||
$errors ++;
|
||||
}
|
||||
}
|
||||
return $errors === 0 ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
|
||||
}
|
||||
protected function runJob(Console\Output\OutputInterface $output, int $job_id): int
|
||||
{
|
||||
$uri = "/api/queue/run/{$job_id}";
|
||||
$output->writeln("GET {$uri}");
|
||||
try {
|
||||
$response = $this->client->get($uri);
|
||||
} catch (ClientExceptionInterface $exception) {
|
||||
$this->logger->error($exception);
|
||||
return Console\Command\Command::FAILURE;
|
||||
}
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
|
||||
return ((int) floor($response->getStatusCode() / 100) === 2) ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
|
||||
try {
|
||||
$this->fastcgi->get($uri);
|
||||
return self::SUCCESS;
|
||||
} catch (FastCGIException $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['uri' => $uri, 'exception' =>$exception]);
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user