1 | <?php |
||
12 | class JobManager extends BaseJobManager |
||
13 | { |
||
14 | 3 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
|
35 | |||
36 | /** |
||
37 | * @param string $objectName |
||
38 | */ |
||
39 | 7 | public function stopIdGenerator($objectName) |
|
47 | |||
48 | /** |
||
49 | * @param string|null $workerName |
||
50 | * @param string|null $method |
||
51 | */ |
||
52 | public function pruneErroneousJobs($workerName = null, $method = null) |
||
59 | |||
60 | /** |
||
61 | * Prunes jobs according to a condition function. |
||
62 | * |
||
63 | * @param string|null $workerName |
||
64 | * @param string|null $method |
||
65 | * @param $conditionFunc |
||
66 | * |
||
67 | * @return int |
||
68 | */ |
||
69 | 3 | protected function pruneJobs($workerName = null, $method = null, $objectName, $conditionFunc) |
|
93 | |||
94 | /** |
||
95 | * Prunes expired jobs. |
||
96 | * |
||
97 | * @param string|null $workerName |
||
98 | * @param string|null $method |
||
99 | */ |
||
100 | public function pruneExpiredJobs($workerName = null, $method = null) |
||
107 | |||
108 | /** |
||
109 | * Removes archived jobs older than $olderThan. |
||
110 | * |
||
111 | * @param \DateTime $olderThan |
||
112 | */ |
||
113 | 1 | public function pruneArchivedJobs(\DateTime $olderThan) |
|
130 | |||
131 | 1 | public function getJobCount($workerName = null, $method = null) |
|
159 | |||
160 | /** |
||
161 | * Get Status Jobs. |
||
162 | * |
||
163 | * @param string $documentName |
||
164 | */ |
||
165 | protected function getStatusByDocument($documentName) |
||
166 | { |
||
167 | // Run a map reduce function get worker and status break down |
||
168 | $mapFunc = "function() { |
||
169 | var result = {}; |
||
170 | result[this.status] = 1; |
||
171 | var key = this.worker_name + '->' + this.method + '()'; |
||
172 | emit(key, result); |
||
173 | }"; |
||
174 | $reduceFunc = 'function(k, vals) { |
||
175 | var result = {}; |
||
176 | for (var index in vals) { |
||
177 | var val = vals[index]; |
||
178 | for (var i in val) { |
||
179 | if (result.hasOwnProperty(i)) { |
||
180 | result[i] += val[i]; |
||
181 | } |
||
182 | else { |
||
183 | result[i] = val[i]; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | return result; |
||
188 | }'; |
||
189 | /** @var DocumentManager $objectManager */ |
||
190 | $objectManager = $this->getObjectManager(); |
||
191 | $qb = $objectManager->createQueryBuilder($documentName); |
||
192 | $qb->map($mapFunc) |
||
193 | ->reduce($reduceFunc); |
||
194 | $query = $qb->getQuery(); |
||
195 | $results = $query->execute(); |
||
196 | |||
197 | $allStatus = array( |
||
198 | BaseJob::STATUS_ERROR => 0, |
||
199 | BaseJob::STATUS_NEW => 0, |
||
200 | BaseJob::STATUS_RUNNING => 0, |
||
201 | BaseJob::STATUS_SUCCESS => 0, |
||
202 | ); |
||
203 | |||
204 | $status = []; |
||
205 | |||
206 | foreach ($results as $info) { |
||
207 | $status[$info['_id']] = $info['value'] + $allStatus; |
||
208 | } |
||
209 | |||
210 | return $status; |
||
211 | } |
||
212 | |||
213 | public function getStatus() |
||
231 | |||
232 | /** |
||
233 | * Get the next job to run (can be filtered by workername and method name). |
||
234 | * |
||
235 | * @param string $workerName |
||
236 | * @param string $methodName |
||
237 | * @param bool $prioritize |
||
238 | * |
||
239 | * @return \Dtc\QueueBundle\Model\Job |
||
240 | */ |
||
241 | 7 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
287 | } |
||
288 |