1 | <?php |
||
11 | class JobManager extends BaseJobManager |
||
12 | { |
||
13 | use CommonTrait; |
||
14 | |||
15 | 3 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
|
16 | { |
||
17 | /** @var DocumentManager $objectManager */ |
||
18 | 3 | $objectManager = $this->getObjectManager(); |
|
19 | 3 | $qb = $objectManager->createQueryBuilder($objectName); |
|
20 | $qb |
||
21 | 3 | ->find() |
|
22 | 3 | ->field('status')->equals($status); |
|
23 | |||
24 | 3 | $this->addWorkerNameCriterion($qb, $workerName, $method); |
|
25 | 3 | $query = $qb->getQuery(); |
|
26 | |||
27 | 3 | return $query->count(); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param string|null $workerName |
||
32 | * @param string|null $method |
||
33 | */ |
||
34 | 1 | public function pruneErroneousJobs($workerName = null, $method = null) |
|
35 | { |
||
36 | /** @var DocumentManager $objectManager */ |
||
37 | 1 | $objectManager = $this->getObjectManager(); |
|
38 | 1 | $qb = $objectManager->createQueryBuilder($this->getArchiveObjectName()); |
|
39 | 1 | $qb = $qb->remove(); |
|
40 | 1 | $qb->field('status')->equals(BaseJob::STATUS_ERROR); |
|
41 | 1 | $this->addWorkerNameCriterion($qb, $workerName, $method); |
|
42 | |||
43 | 1 | $query = $qb->getQuery(); |
|
44 | 1 | $result = $query->execute(); |
|
45 | 1 | if (isset($result['n'])) { |
|
46 | 1 | return $result['n']; |
|
47 | } |
||
48 | |||
49 | return 0; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param Builder $builder |
||
54 | * @param string|null $workerName |
||
55 | * @param string|null $method |
||
56 | */ |
||
57 | 14 | protected function addWorkerNameCriterion(Builder $builder, $workerName = null, $method = null) |
|
58 | { |
||
59 | 14 | if (null !== $workerName) { |
|
60 | 4 | $builder->field('workerName')->equals($workerName); |
|
61 | 4 | } |
|
62 | |||
63 | 14 | if (null !== $method) { |
|
64 | 3 | $builder->field('method')->equals($method); |
|
65 | 3 | } |
|
66 | 14 | } |
|
67 | |||
68 | /** |
||
69 | * @param null $workerName |
||
70 | * @param null $method |
||
71 | * |
||
72 | * @return int |
||
73 | */ |
||
74 | 2 | protected function updateExpired($workerName = null, $method = null) |
|
92 | |||
93 | /** |
||
94 | * Removes archived jobs older than $olderThan. |
||
95 | * |
||
96 | * @param \DateTime $olderThan |
||
97 | * return int |
||
98 | */ |
||
99 | 1 | public function pruneArchivedJobs(\DateTime $olderThan) |
|
103 | |||
104 | 2 | public function getJobCount($workerName = null, $method = null) |
|
105 | { |
||
106 | /** @var DocumentManager $objectManager */ |
||
107 | 2 | $objectManager = $this->getObjectManager(); |
|
108 | 2 | $qb = $objectManager->createQueryBuilder($this->getObjectName()); |
|
109 | $qb |
||
110 | 2 | ->find(); |
|
111 | |||
112 | 2 | $this->addWorkerNameCriterion($qb, $workerName, $method); |
|
113 | |||
114 | // Filter |
||
115 | 2 | $date = new \DateTime(); |
|
116 | $qb |
||
117 | 2 | ->addAnd( |
|
118 | 2 | $qb->expr()->addOr($qb->expr()->field('expiresAt')->equals(null), $qb->expr()->field('expiresAt')->gt($date)) |
|
119 | 2 | ) |
|
120 | 2 | ->field('locked')->equals(null); |
|
121 | |||
122 | 2 | $query = $qb->getQuery(); |
|
123 | |||
124 | 2 | return $query->count(true); |
|
125 | } |
||
126 | |||
127 | 1 | protected function getJobCurrentStatus(\Dtc\QueueBundle\Model\Job $job) |
|
138 | |||
139 | /** |
||
140 | * Get Status Jobs. |
||
141 | * |
||
142 | * @param string $documentName |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | 2 | protected function getStatusByDocument($documentName) |
|
197 | |||
198 | 2 | public function getStatus() |
|
216 | |||
217 | /** |
||
218 | * Get the next job to run (can be filtered by workername and method name). |
||
219 | * |
||
220 | * @param string $workerName |
||
221 | * @param string $methodName |
||
222 | * @param bool $prioritize |
||
223 | * |
||
224 | * @return \Dtc\QueueBundle\Model\Job |
||
225 | */ |
||
226 | 7 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
268 | |||
269 | 1 | protected function updateNearestBatch(\Dtc\QueueBundle\Model\Job $job) |
|
312 | } |
||
313 |