|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Shippinno\Job\Infrastructure\Application\Messaging; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
use Shippinno\Job\Application\Messaging\JobFlight; |
|
7
|
|
|
use Shippinno\Job\Application\Messaging\JobFlightManager; |
|
8
|
|
|
|
|
9
|
|
|
class DoctrineJobFlightManager extends EntityRepository implements JobFlightManager |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* {@inheritdoc} |
|
13
|
|
|
*/ |
|
14
|
|
|
public function departed(int $jobId, string $queue): void |
|
15
|
|
|
{ |
|
16
|
|
|
$this->getEntityManager()->persist(new JobFlight($jobId, $queue)); |
|
17
|
|
|
$this->getEntityManager()->flush(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
public function latestJobFlightOfJobId(int $jobId): JobFlight |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->findOneBy(['jobId' => $jobId], ['id' => 'DESC']); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function acknowledged(int $jobId): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->latestJobFlightOfJobId($jobId)->acknowledge(); |
|
34
|
|
|
$this->getEntityManager()->flush(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function abandoned(int $jobId): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->latestJobFlightOfJobId($jobId)->abandoned(); |
|
43
|
|
|
$this->getEntityManager()->flush(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function requeued(int $jobId): void |
|
50
|
|
|
{ |
|
51
|
|
|
$jobFlight = $this->latestJobFlightOfJobId($jobId); |
|
52
|
|
|
$jobFlight->requeued(); |
|
53
|
|
|
$this->departed($jobFlight->jobId(), $jobFlight->queue()); |
|
54
|
|
|
$this->getEntityManager()->flush(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function rejected(int $jobId): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->latestJobFlightOfJobId($jobId)->rejected(); |
|
63
|
|
|
$this->getEntityManager()->flush(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function letGo(int $jobId): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->latestJobFlightOfJobId($jobId)->letGo(); |
|
72
|
|
|
$this->getEntityManager()->flush(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|