Merge "MimeAnalyzer: Add testcases for mp3 detection"
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueSecondTestQueue.php
1 <?php
2
3 /**
4 * A wrapper for the JobQueue that delegates all the method calls to a single,
5 * main queue, and also pushes all the jobs to a second job queue that's being
6 * debugged.
7 *
8 * This class was temporary added to test transitioning to the JobQueueEventBus
9 * and will removed after the transition is completed. This code is only needed
10 * while we are testing the new infrastructure to be able to compare the results
11 * between the queue implementations and make sure that they process the same jobs,
12 * deduplicate correctly, compare the delays, backlogs and make sure no jobs are lost.
13 * When the new infrastructure is well tested this will not be needed any more.
14 *
15 * @deprecated since 1.30
16 * @since 1.30
17 */
18 class JobQueueSecondTestQueue extends JobQueue {
19
20 /**
21 * @var JobQueue
22 */
23 private $mainQueue;
24
25 /**
26 * @var JobQueue
27 */
28 private $debugQueue;
29
30 protected function __construct( array $params ) {
31 if ( !isset( $params['mainqueue'] ) ) {
32 throw new MWException( "mainqueue parameter must be provided to the debug queue" );
33 }
34
35 if ( !isset( $params['debugqueue'] ) ) {
36 throw new MWException( "debugqueue parameter must be provided to the debug queue" );
37 }
38
39 $conf = [ 'wiki' => $params['wiki'], 'type' => $params['type'] ];
40 $this->mainQueue = JobQueue::factory( $params['mainqueue'] + $conf );
41 $this->debugQueue = JobQueue::factory( $params['debugqueue'] + $conf );
42
43 // We need to construct parent after creating the main and debug queue
44 // because super constructor calls some methods we delegate to the main queue.
45 parent::__construct( $params );
46 }
47
48 /**
49 * Get the allowed queue orders for configuration validation
50 *
51 * @return array Subset of (random, timestamp, fifo, undefined)
52 */
53 protected function supportedOrders() {
54 return $this->mainQueue->supportedOrders();
55 }
56
57 /**
58 * Get the default queue order to use if configuration does not specify one
59 *
60 * @return string One of (random, timestamp, fifo, undefined)
61 */
62 protected function optimalOrder() {
63 return $this->mainQueue->optimalOrder();
64 }
65
66 /**
67 * Find out if delayed jobs are supported for configuration validation
68 *
69 * @return bool Whether delayed jobs are supported
70 */
71 protected function supportsDelayedJobs() {
72 return $this->mainQueue->supportsDelayedJobs();
73 }
74
75 /**
76 * @see JobQueue::isEmpty()
77 * @return bool
78 */
79 protected function doIsEmpty() {
80 return $this->mainQueue->doIsEmpty();
81 }
82
83 /**
84 * @see JobQueue::getSize()
85 * @return int
86 */
87 protected function doGetSize() {
88 return $this->mainQueue->doGetSize();
89 }
90
91 /**
92 * @see JobQueue::getAcquiredCount()
93 * @return int
94 */
95 protected function doGetAcquiredCount() {
96 return $this->mainQueue->doGetAcquiredCount();
97 }
98
99 /**
100 * @see JobQueue::getDelayedCount()
101 * @return int
102 */
103 protected function doGetDelayedCount() {
104 return $this->mainQueue->doGetDelayedCount();
105 }
106
107 /**
108 * @see JobQueue::getAbandonedCount()
109 * @return int
110 */
111 protected function doGetAbandonedCount() {
112 return $this->mainQueue->doGetAbandonedCount();
113 }
114
115 /**
116 * @see JobQueue::batchPush()
117 * @param IJobSpecification[] $jobs
118 * @param int $flags
119 */
120 protected function doBatchPush( array $jobs, $flags ) {
121 $this->mainQueue->doBatchPush( $jobs, $flags );
122
123 try {
124 $this->debugQueue->doBatchPush( $jobs, $flags );
125 } catch ( Exception $exception ) {
126 MWExceptionHandler::logException( $exception );
127 }
128 }
129
130 /**
131 * @see JobQueue::pop()
132 * @return Job|bool
133 */
134 protected function doPop() {
135 return $this->mainQueue->doPop();
136 }
137
138 /**
139 * @see JobQueue::ack()
140 * @param Job $job
141 */
142 protected function doAck( Job $job ) {
143 return $this->mainQueue->doAck( $job );
144 }
145
146 /**
147 * @see JobQueue::deduplicateRootJob()
148 * @param IJobSpecification $job
149 * @throws MWException
150 * @return bool
151 */
152 protected function doDeduplicateRootJob( IJobSpecification $job ) {
153 return $this->mainQueue->doDeduplicateRootJob( $job );
154 }
155
156 /**
157 * @see JobQueue::isRootJobOldDuplicate()
158 * @param Job $job
159 * @return bool
160 */
161 protected function doIsRootJobOldDuplicate( Job $job ) {
162 return $this->mainQueue->doIsRootJobOldDuplicate( $job );
163 }
164
165 /**
166 * @param string $signature Hash identifier of the root job
167 * @return string
168 */
169 protected function getRootJobCacheKey( $signature ) {
170 return $this->mainQueue->getRootJobCacheKey( $signature );
171 }
172
173 /**
174 * @see JobQueue::delete()
175 * @throws MWException
176 */
177 protected function doDelete() {
178 return $this->mainQueue->doDelete();
179 }
180
181 /**
182 * @see JobQueue::waitForBackups()
183 * @return void
184 */
185 protected function doWaitForBackups() {
186 $this->mainQueue->doWaitForBackups();
187 }
188
189 /**
190 * @see JobQueue::flushCaches()
191 * @return void
192 */
193 protected function doFlushCaches() {
194 $this->mainQueue->doFlushCaches();
195 }
196
197 /**
198 * Get an iterator to traverse over all available jobs in this queue.
199 * This does not include jobs that are currently acquired or delayed.
200 * Note: results may be stale if the queue is concurrently modified.
201 *
202 * @return Iterator
203 * @throws JobQueueError
204 */
205 public function getAllQueuedJobs() {
206 return $this->mainQueue->getAllQueuedJobs();
207 }
208
209 /**
210 * Get an iterator to traverse over all delayed jobs in this queue.
211 * Note: results may be stale if the queue is concurrently modified.
212 *
213 * @return Iterator
214 * @throws JobQueueError
215 * @since 1.22
216 */
217 public function getAllDelayedJobs() {
218 return $this->mainQueue->getAllDelayedJobs();
219 }
220
221 /**
222 * Get an iterator to traverse over all claimed jobs in this queue
223 *
224 * Callers should be quick to iterator over it or few results
225 * will be returned due to jobs being acknowledged and deleted
226 *
227 * @return Iterator
228 * @throws JobQueueError
229 * @since 1.26
230 */
231 public function getAllAcquiredJobs() {
232 return $this->mainQueue->getAllAcquiredJobs();
233 }
234
235 /**
236 * Get an iterator to traverse over all abandoned jobs in this queue
237 *
238 * @return Iterator
239 * @throws JobQueueError
240 * @since 1.25
241 */
242 public function getAllAbandonedJobs() {
243 return $this->mainQueue->getAllAbandonedJobs();
244 }
245
246 /**
247 * Do not use this function outside of JobQueue/JobQueueGroup
248 *
249 * @return string
250 * @since 1.22
251 */
252 public function getCoalesceLocationInternal() {
253 return $this->mainQueue->getCoalesceLocationInternal();
254 }
255
256 /**
257 * @see JobQueue::getSiblingQueuesWithJobs()
258 * @param array $types List of queues types
259 * @return array|null (list of queue types) or null if unsupported
260 */
261 protected function doGetSiblingQueuesWithJobs( array $types ) {
262 return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
263 }
264
265 /**
266 * @see JobQueue::getSiblingQueuesSize()
267 * @param array $types List of queues types
268 * @return array|null (list of queue types) or null if unsupported
269 */
270 protected function doGetSiblingQueueSizes( array $types ) {
271 return $this->mainQueue->doGetSiblingQueueSizes( $types );
272 }
273
274 /**
275 * @throws JobQueueReadOnlyError
276 */
277 protected function assertNotReadOnly() {
278 $this->mainQueue->assertNotReadOnly();
279 }
280 }