1 | <?php |
||
11 | class JobManager extends BaseJobManager |
||
12 | { |
||
13 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
||
14 | { |
||
15 | /** @var DocumentManager $objectManager */ |
||
16 | $objectManager = $this->getObjectManager(); |
||
17 | $qb = $objectManager->createQueryBuilder($objectName); |
||
18 | $qb |
||
19 | ->find() |
||
20 | ->field('status')->equals($status); |
||
21 | |||
22 | if (null !== $workerName) { |
||
23 | $qb->field('workerName')->equals($workerName); |
||
24 | } |
||
25 | |||
26 | if (null !== $method) { |
||
27 | $qb->field('method')->equals($method); |
||
28 | } |
||
29 | |||
30 | $query = $qb->getQuery(); |
||
31 | |||
32 | return $query->count(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $objectName |
||
37 | */ |
||
38 | public function stopIdGenerator($objectName) |
||
39 | { |
||
40 | $objectManager = $this->getObjectManager(); |
||
41 | $repository = $objectManager->getRepository($objectName); |
||
42 | /** @var ClassMetadata $metadata */ |
||
43 | $metadata = $this->getObjectManager()->getClassMetadata($repository->getClassName()); |
||
44 | $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param string $workerName |
||
49 | * @param string $method |
||
50 | */ |
||
51 | public function pruneErroneousJobs($workerName = null, $method = null) |
||
52 | { |
||
53 | return $this->pruneJobs($workerName, $method, $this->getArchiveObjectName(), function ($qb) { |
||
54 | /* @var Builder $qb */ |
||
55 | return $qb->field('status')->equals(Job::STATUS_ERROR); |
||
56 | }); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Prunes jobs according to a condition function. |
||
61 | * |
||
62 | * @param null $workerName |
||
63 | * @param null $method |
||
64 | * @param $conditionFunc |
||
65 | * |
||
66 | * @return int |
||
67 | */ |
||
68 | protected function pruneJobs($workerName = null, $method = null, $objectName, $conditionFunc) |
||
69 | { |
||
70 | /** @var DocumentManager $objectManager */ |
||
71 | $objectManager = $this->getObjectManager(); |
||
72 | $qb = $objectManager->createQueryBuilder($objectName); |
||
73 | $qb = $qb->remove(); |
||
74 | $qb = $conditionFunc($qb); |
||
75 | |||
76 | if (null !== $workerName) { |
||
77 | $qb->field('workerName')->equals($workerName); |
||
78 | } |
||
79 | |||
80 | if (null !== $method) { |
||
81 | $qb->field('method')->equals($method); |
||
82 | } |
||
83 | |||
84 | $query = $qb->getQuery(); |
||
85 | $result = $query->execute(); |
||
86 | if (isset($result['n'])) { |
||
87 | return $result['n']; |
||
88 | } |
||
89 | |||
90 | return 0; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Prunes expired jobs. |
||
95 | * |
||
96 | * @param string $workerName |
||
97 | * @param string $method |
||
98 | */ |
||
99 | public function pruneExpiredJobs($workerName = null, $method = null) |
||
100 | { |
||
101 | return $this->pruneJobs($workerName, $method, $this->getObjectName(), function ($qb) { |
||
102 | /* @var Builder $qb */ |
||
103 | return $qb->field('expiresAt')->lte(new \DateTime()); |
||
104 | }); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Removes archived jobs older than $olderThan. |
||
109 | * |
||
110 | * @param \DateTime $olderThan |
||
111 | */ |
||
112 | public function pruneArchivedJobs(\DateTime $olderThan) |
||
129 | |||
130 | public function getJobCount($workerName = null, $method = null) |
||
158 | |||
159 | /** |
||
160 | * Get Status Jobs. |
||
161 | * |
||
162 | * @param string $documentName |
||
163 | */ |
||
164 | protected function getStatusByDocument($documentName) |
||
211 | |||
212 | public function getStatus() |
||
230 | |||
231 | /** |
||
232 | * Get the next job to run (can be filtered by workername and method name). |
||
233 | * |
||
234 | * @param string $workerName |
||
235 | * @param string $methodName |
||
236 | * @param bool $prioritize |
||
237 | * |
||
238 | * @return \Dtc\QueueBundle\Model\Job |
||
239 | */ |
||
240 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
||
286 | } |
||
287 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.