Job Queue

This commit is contained in:
Juan Pablo Vial
2025-05-10 12:30:35 -04:00
parent 61324f159b
commit 8b2de31e02
6 changed files with 251 additions and 0 deletions

51
app/src/Service/Job.php Normal file
View File

@ -0,0 +1,51 @@
<?php
namespace Incoviba\Service;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\{Create,Read};
use Incoviba\Repository;
use Incoviba\Model;
class Job extends Ideal\Service
{
public function __construct(LoggerInterface $logger, protected Repository\Job $jobRepository)
{
parent::__construct($logger);
}
/**
* @param array $configuration
* @return Model\Job
* @throws Create
*/
public function add(array $configuration): Model\Job
{
try {
$job = $this->jobRepository->create(compact('configuration'));
return $this->process($this->jobRepository->save($job));
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
}
/**
* @return array
* @throws Read
*/
public function getPending(): array
{
try {
return array_merge([$this, 'process'],$this->jobRepository->fetchPending());
} catch (EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
}
protected function process(Model\Job $job): Model\Job
{
return $job;
}
}