1 | <?php |
||
12 | class JobManager extends BaseJobManager |
||
13 | { |
||
14 | use CommonTrait; |
||
15 | |||
16 | 3 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
|
17 | { |
||
18 | /** @var DocumentManager $objectManager */ |
||
19 | 3 | $objectManager = $this->getObjectManager(); |
|
20 | 3 | $qb = $objectManager->createQueryBuilder($objectName); |
|
21 | $qb |
||
22 | 3 | ->find() |
|
23 | 3 | ->field('status')->equals($status); |
|
24 | |||
25 | 3 | $this->addWorkerNameCriterion($qb, $workerName, $method); |
|
26 | 3 | $query = $qb->getQuery(); |
|
27 | |||
28 | 3 | return $query->count(); |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param string|null $workerName |
||
33 | * @param string|null $method |
||
34 | */ |
||
35 | 1 | public function pruneErroneousJobs($workerName = null, $method = null) |
|
36 | { |
||
37 | /** @var DocumentManager $objectManager */ |
||
38 | 1 | $objectManager = $this->getObjectManager(); |
|
39 | 1 | $qb = $objectManager->createQueryBuilder($this->getArchiveObjectName()); |
|
40 | 1 | $qb = $qb->remove(); |
|
41 | 1 | $qb->field('status')->equals(BaseJob::STATUS_ERROR); |
|
42 | 1 | $this->addWorkerNameCriterion($qb, $workerName, $method); |
|
43 | |||
44 | 1 | $query = $qb->getQuery(); |
|
45 | 1 | $result = $query->execute(); |
|
46 | 1 | if (isset($result['n'])) { |
|
47 | 1 | return $result['n']; |
|
48 | } |
||
49 | |||
50 | return 0; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param Builder $builder |
||
55 | * @param string|null $workerName |
||
56 | * @param string|null $method |
||
57 | */ |
||
58 | 15 | protected function addWorkerNameCriterion(Builder $builder, $workerName = null, $method = null) |
|
59 | { |
||
60 | 15 | if (null !== $workerName) { |
|
61 | 4 | $builder->field('workerName')->equals($workerName); |
|
62 | 4 | } |
|
63 | |||
64 | 15 | if (null !== $method) { |
|
65 | 3 | $builder->field('method')->equals($method); |
|
66 | 3 | } |
|
67 | 15 | } |
|
68 | |||
69 | /** |
||
70 | * @param null $workerName |
||
71 | * @param null $method |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | 2 | protected function updateExpired($workerName = null, $method = null) |
|
93 | |||
94 | /** |
||
95 | * Removes archived jobs older than $olderThan. |
||
96 | * |
||
97 | * @param \DateTime $olderThan |
||
98 | * return int |
||
99 | */ |
||
100 | 1 | public function pruneArchivedJobs(\DateTime $olderThan) |
|
107 | |||
108 | 2 | public function getJobCount($workerName = null, $method = null) |
|
130 | |||
131 | /** |
||
132 | * Get Status Jobs. |
||
133 | * |
||
134 | * @param string $documentName |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | 2 | protected function getStatusByDocument($documentName) |
|
189 | |||
190 | 2 | public function getStatus() |
|
208 | |||
209 | /** |
||
210 | * Get the next job to run (can be filtered by workername and method name). |
||
211 | * |
||
212 | * @param string $workerName |
||
213 | * @param string $methodName |
||
214 | * @param bool $prioritize |
||
215 | * |
||
216 | * @return \Dtc\QueueBundle\Model\Job |
||
217 | */ |
||
218 | 8 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
257 | } |
||
258 |