1 | <?php |
||
12 | class JobManager extends BaseJobManager |
||
13 | { |
||
14 | 3 | public function countJobsByStatus($objectName, $status, $workerName = null, $method = null) |
|
28 | |||
29 | /** |
||
30 | * @param string $objectName |
||
31 | */ |
||
32 | 9 | public function stopIdGenerator($objectName) |
|
36 | |||
37 | 1 | public function restoreIdGenerator($objectName) |
|
41 | |||
42 | /** |
||
43 | * @param string|null $workerName |
||
44 | * @param string|null $method |
||
45 | */ |
||
46 | 1 | public function pruneErroneousJobs($workerName = null, $method = null) |
|
63 | |||
64 | 10 | protected function addWorkerNameCriterion(Builder $builder, $workerName = null, $method = null) |
|
74 | |||
75 | 1 | protected function updateExpired($workerName = null, $method = null) |
|
93 | |||
94 | /** |
||
95 | * Removes archived jobs older than $olderThan. |
||
96 | * |
||
97 | * @param \DateTime $olderThan |
||
98 | */ |
||
99 | 1 | public function pruneArchivedJobs(\DateTime $olderThan) |
|
116 | |||
117 | 1 | public function getJobCount($workerName = null, $method = null) |
|
139 | |||
140 | /** |
||
141 | * Get Status Jobs. |
||
142 | * |
||
143 | * @param string $documentName |
||
144 | */ |
||
145 | 1 | protected function getStatusByDocument($documentName) |
|
146 | { |
||
147 | // Run a map reduce function get worker and status break down |
||
148 | 1 | $mapFunc = "function() { |
|
149 | var result = {}; |
||
150 | result[this.status] = 1; |
||
151 | var key = this.worker_name + '->' + this.method + '()'; |
||
152 | emit(key, result); |
||
153 | }"; |
||
154 | 1 | $reduceFunc = 'function(k, vals) { |
|
155 | var result = {}; |
||
156 | for (var index in vals) { |
||
157 | var val = vals[index]; |
||
158 | for (var i in val) { |
||
159 | if (result.hasOwnProperty(i)) { |
||
160 | result[i] += val[i]; |
||
161 | } |
||
162 | else { |
||
163 | result[i] = val[i]; |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | return result; |
||
168 | }'; |
||
169 | /** @var DocumentManager $objectManager */ |
||
170 | 1 | $objectManager = $this->getObjectManager(); |
|
171 | 1 | $qb = $objectManager->createQueryBuilder($documentName); |
|
172 | 1 | $qb->map($mapFunc) |
|
173 | 1 | ->reduce($reduceFunc); |
|
174 | 1 | $query = $qb->getQuery(); |
|
175 | 1 | $results = $query->execute(); |
|
176 | |||
177 | $allStatus = array( |
||
178 | 1 | BaseJob::STATUS_ERROR => 0, |
|
179 | 1 | BaseJob::STATUS_NEW => 0, |
|
180 | 1 | RetryableJob::STATUS_EXPIRED => 0, |
|
181 | 1 | RetryableJob::STATUS_MAX_ERROR => 0, |
|
182 | 1 | RetryableJob::STATUS_MAX_RETRIES => 0, |
|
183 | 1 | RetryableJob::STATUS_MAX_STALLED => 0, |
|
184 | 1 | BaseJob::STATUS_RUNNING => 0, |
|
185 | 1 | BaseJob::STATUS_SUCCESS => 0, |
|
186 | ); |
||
187 | |||
188 | 1 | $status = []; |
|
189 | |||
190 | 1 | foreach ($results as $info) { |
|
191 | 1 | $status[$info['_id']] = $info['value'] + $allStatus; |
|
192 | } |
||
193 | |||
194 | 1 | return $status; |
|
195 | } |
||
196 | |||
197 | 1 | public function getStatus() |
|
215 | |||
216 | /** |
||
217 | * Get the next job to run (can be filtered by workername and method name). |
||
218 | * |
||
219 | * @param string $workerName |
||
220 | * @param string $methodName |
||
221 | * @param bool $prioritize |
||
222 | * |
||
223 | * @return \Dtc\QueueBundle\Model\Job |
||
224 | */ |
||
225 | 5 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
264 | } |
||
265 |