-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJobGateway.php
More file actions
52 lines (39 loc) · 1.44 KB
/
JobGateway.php
File metadata and controls
52 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace CodeRhapsodie\DataflowBundle\Gateway;
use CodeRhapsodie\DataflowBundle\Entity\Job;
use CodeRhapsodie\DataflowBundle\ExceptionsHandler\ExceptionHandlerInterface;
use CodeRhapsodie\DataflowBundle\ExceptionsHandler\NullExceptionHandler;
use CodeRhapsodie\DataflowBundle\Repository\JobRepository;
class JobGateway
{
public function __construct(private JobRepository $repository, private ExceptionHandlerInterface $exceptionHandler)
{
}
public function find(int $jobId): ?Job
{
$job = $this->repository->find($jobId);
return $this->loadExceptions($job);
}
public function save(Job $job): void
{
if (!$this->exceptionHandler instanceof NullExceptionHandler) {
$this->exceptionHandler->save($job->getId(), $job->getExceptions());
$job->setExceptions([]);
}
$this->repository->save($job);
}
public function findLastForDataflowId(int $scheduleId): ?Job
{
$job = $this->repository->findLastForDataflowId($scheduleId);
return $this->loadExceptions($job);
}
private function loadExceptions(?Job $job): ?Job
{
if ($job === null || $this->exceptionHandler instanceof NullExceptionHandler) {
return $job;
}
$this->exceptionHandler->save($job->getId(), $job->getExceptions());
return $job->setExceptions($this->exceptionHandler->find($job->getId()));
}
}