42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
namespace Incoviba\Controller\API;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Incoviba\Common\Ideal;
|
|
use Incoviba\Exception\ServiceAction\Read;
|
|
use Incoviba\Service;
|
|
|
|
class Queues extends Ideal\Controller
|
|
{
|
|
use withJson;
|
|
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
|
Service\Queue $queueService): ResponseInterface
|
|
{
|
|
$output = [
|
|
'success' => false
|
|
];
|
|
if ($queueService->run($request)) {
|
|
$output['success'] = true;
|
|
}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function jobs(ServerRequestInterface $request, ResponseInterface $response,
|
|
Service\Queue $queueService): ResponseInterface
|
|
{
|
|
$output = [
|
|
'jobs' => array_column($queueService->getPendingJobs(), 'id')
|
|
];
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function run(ServerRequestInterface $request, ResponseInterface $response, Service\Queue $queueService,
|
|
int $job_id): ResponseInterface
|
|
{
|
|
if ($queueService->runJob($job_id, $request)) {
|
|
return $response->withStatus(200);
|
|
}
|
|
return $response->withStatus(422);
|
|
}
|
|
}
|