1 | <?php |
||
12 | class JobManager extends BaseJobManager |
||
13 | { |
||
14 | use CommonTrait; |
||
15 | |||
16 | 3 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
|
30 | |||
31 | /** |
||
32 | * @param string $objectName |
||
33 | */ |
||
34 | 12 | public function stopIdGenerator($objectName) |
|
38 | |||
39 | 1 | public function restoreIdGenerator($objectName) |
|
43 | |||
44 | /** |
||
45 | * @param string|null $workerName |
||
46 | * @param string|null $method |
||
47 | */ |
||
48 | 1 | public function pruneErroneousJobs($workerName = null, $method = null) |
|
65 | |||
66 | 14 | protected function addWorkerNameCriterion(Builder $builder, $workerName = null, $method = null) |
|
76 | |||
77 | 2 | protected function updateExpired($workerName = null, $method = null) |
|
95 | |||
96 | /** |
||
97 | * Removes archived jobs older than $olderThan. |
||
98 | * |
||
99 | * @param \DateTime $olderThan |
||
100 | */ |
||
101 | 1 | public function pruneArchivedJobs(\DateTime $olderThan) |
|
105 | |||
106 | 2 | public function getJobCount($workerName = null, $method = null) |
|
128 | |||
129 | /** |
||
130 | * Get Status Jobs. |
||
131 | * |
||
132 | * @param string $documentName |
||
133 | */ |
||
134 | 2 | protected function getStatusByDocument($documentName) |
|
135 | { |
||
136 | // Run a map reduce function get worker and status break down |
||
137 | 2 | $mapFunc = "function() { |
|
138 | var result = {}; |
||
139 | result[this.status] = 1; |
||
140 | var key = this.worker_name + '->' + this.method + '()'; |
||
141 | emit(key, result); |
||
142 | }"; |
||
143 | 2 | $reduceFunc = 'function(k, vals) { |
|
144 | var result = {}; |
||
145 | for (var index in vals) { |
||
146 | var val = vals[index]; |
||
147 | for (var i in val) { |
||
148 | if (result.hasOwnProperty(i)) { |
||
149 | result[i] += val[i]; |
||
150 | } |
||
151 | else { |
||
152 | result[i] = val[i]; |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | return result; |
||
157 | }'; |
||
158 | /** @var DocumentManager $objectManager */ |
||
159 | 2 | $objectManager = $this->getObjectManager(); |
|
160 | 2 | $qb = $objectManager->createQueryBuilder($documentName); |
|
161 | 2 | $qb->map($mapFunc) |
|
162 | 2 | ->reduce($reduceFunc); |
|
163 | 2 | $query = $qb->getQuery(); |
|
164 | 2 | $results = $query->execute(); |
|
165 | |||
166 | $allStatus = array( |
||
167 | 2 | BaseJob::STATUS_ERROR => 0, |
|
168 | BaseJob::STATUS_NEW => 0, |
||
169 | RetryableJob::STATUS_EXPIRED => 0, |
||
170 | RetryableJob::STATUS_MAX_ERROR => 0, |
||
171 | RetryableJob::STATUS_MAX_RETRIES => 0, |
||
172 | RetryableJob::STATUS_MAX_STALLED => 0, |
||
173 | BaseJob::STATUS_RUNNING => 0, |
||
174 | BaseJob::STATUS_SUCCESS => 0, |
||
175 | ); |
||
176 | |||
177 | 2 | $status = []; |
|
178 | |||
179 | 2 | foreach ($results as $info) { |
|
180 | 1 | $status[$info['_id']] = $info['value'] + $allStatus; |
|
181 | } |
||
182 | |||
183 | 2 | return $status; |
|
184 | } |
||
185 | |||
186 | 2 | public function getStatus() |
|
204 | |||
205 | /** |
||
206 | * Get the next job to run (can be filtered by workername and method name). |
||
207 | * |
||
208 | * @param string $workerName |
||
209 | * @param string $methodName |
||
210 | * @param bool $prioritize |
||
211 | * |
||
212 | * @return \Dtc\QueueBundle\Model\Job |
||
213 | */ |
||
214 | 7 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
253 | } |
||
254 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.