Backport WikiMap/JobQueueGroup logic to handle hyphenated DB names
[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 /**
31 * @var bool
32 */
33 private $onlyWriteToDebugQueue;
34
35 protected function __construct( array $params ) {
36 if ( !isset( $params['mainqueue'] ) ) {
37 throw new MWException( "mainqueue parameter must be provided to the debug queue" );
38 }
39
40 if ( !isset( $params['debugqueue'] ) ) {
41 throw new MWException( "debugqueue parameter must be provided to the debug queue" );
42 }
43
44 $conf = [ 'wiki' => $params['wiki'], 'type' => $params['type'] ];
45 $this->mainQueue = JobQueue::factory( $params['mainqueue'] + $conf );
46 $this->debugQueue = JobQueue::factory( $params['debugqueue'] + $conf );
47 $this->onlyWriteToDebugQueue = isset( $params['readonly'] ) ? $params['readonly'] : false;
48
49 // We need to construct parent after creating the main and debug queue
50 // because super constructor calls some methods we delegate to the main queue.
51 parent::__construct( $params );
52 }
53
54 /**
55 * Get the allowed queue orders for configuration validation
56 *
57 * @return array Subset of (random, timestamp, fifo, undefined)
58 */
59 protected function supportedOrders() {
60 return $this->mainQueue->supportedOrders();
61 }
62
63 /**
64 * Get the default queue order to use if configuration does not specify one
65 *
66 * @return string One of (random, timestamp, fifo, undefined)
67 */
68 protected function optimalOrder() {
69 return $this->mainQueue->optimalOrder();
70 }
71
72 /**
73 * Find out if delayed jobs are supported for configuration validation
74 *
75 * @return bool Whether delayed jobs are supported
76 */
77 protected function supportsDelayedJobs() {
78 return $this->mainQueue->supportsDelayedJobs();
79 }
80
81 /**
82 * @see JobQueue::isEmpty()
83 * @return bool
84 */
85 protected function doIsEmpty() {
86 return $this->mainQueue->doIsEmpty();
87 }
88
89 /**
90 * @see JobQueue::getSize()
91 * @return int
92 */
93 protected function doGetSize() {
94 return $this->mainQueue->doGetSize();
95 }
96
97 /**
98 * @see JobQueue::getAcquiredCount()
99 * @return int
100 */
101 protected function doGetAcquiredCount() {
102 return $this->mainQueue->doGetAcquiredCount();
103 }
104
105 /**
106 * @see JobQueue::getDelayedCount()
107 * @return int
108 */
109 protected function doGetDelayedCount() {
110 return $this->mainQueue->doGetDelayedCount();
111 }
112
113 /**
114 * @see JobQueue::getAbandonedCount()
115 * @return int
116 */
117 protected function doGetAbandonedCount() {
118 return $this->mainQueue->doGetAbandonedCount();
119 }
120
121 /**
122 * @see JobQueue::batchPush()
123 * @param IJobSpecification[] $jobs
124 * @param int $flags
125 */
126 protected function doBatchPush( array $jobs, $flags ) {
127 if ( !$this->onlyWriteToDebugQueue ) {
128 $this->mainQueue->doBatchPush( $jobs, $flags );
129 }
130
131 try {
132 $this->debugQueue->doBatchPush( $jobs, $flags );
133 } catch ( Exception $exception ) {
134 MWExceptionHandler::logException( $exception );
135 }
136 }
137
138 /**
139 * @see JobQueue::pop()
140 * @return Job|bool
141 */
142 protected function doPop() {
143 return $this->mainQueue->doPop();
144 }
145
146 /**
147 * @see JobQueue::ack()
148 * @param Job $job
149 * @return Job|bool
150 */
151 protected function doAck( Job $job ) {
152 return $this->mainQueue->doAck( $job );
153 }
154
155 /**
156 * @see JobQueue::deduplicateRootJob()
157 * @param IJobSpecification $job
158 * @throws MWException
159 * @return bool
160 */
161 protected function doDeduplicateRootJob( IJobSpecification $job ) {
162 return $this->mainQueue->doDeduplicateRootJob( $job );
163 }
164
165 /**
166 * @see JobQueue::isRootJobOldDuplicate()
167 * @param Job $job
168 * @return bool
169 */
170 protected function doIsRootJobOldDuplicate( Job $job ) {
171 return $this->mainQueue->doIsRootJobOldDuplicate( $job );
172 }
173
174 /**
175 * @param string $signature Hash identifier of the root job
176 * @return string
177 */
178 protected function getRootJobCacheKey( $signature ) {
179 return $this->mainQueue->getRootJobCacheKey( $signature );
180 }
181
182 /**
183 * @see JobQueue::delete()
184 * @return bool
185 * @throws MWException
186 */
187 protected function doDelete() {
188 return $this->mainQueue->doDelete();
189 }
190
191 /**
192 * @see JobQueue::waitForBackups()
193 * @return void
194 */
195 protected function doWaitForBackups() {
196 $this->mainQueue->doWaitForBackups();
197 }
198
199 /**
200 * @see JobQueue::flushCaches()
201 * @return void
202 */
203 protected function doFlushCaches() {
204 $this->mainQueue->doFlushCaches();
205 }
206
207 /**
208 * Get an iterator to traverse over all available jobs in this queue.
209 * This does not include jobs that are currently acquired or delayed.
210 * Note: results may be stale if the queue is concurrently modified.
211 *
212 * @return Iterator
213 * @throws JobQueueError
214 */
215 public function getAllQueuedJobs() {
216 return $this->mainQueue->getAllQueuedJobs();
217 }
218
219 /**
220 * Get an iterator to traverse over all delayed jobs in this queue.
221 * Note: results may be stale if the queue is concurrently modified.
222 *
223 * @return Iterator
224 * @throws JobQueueError
225 * @since 1.22
226 */
227 public function getAllDelayedJobs() {
228 return $this->mainQueue->getAllDelayedJobs();
229 }
230
231 /**
232 * Get an iterator to traverse over all claimed jobs in this queue
233 *
234 * Callers should be quick to iterator over it or few results
235 * will be returned due to jobs being acknowledged and deleted
236 *
237 * @return Iterator
238 * @throws JobQueueError
239 * @since 1.26
240 */
241 public function getAllAcquiredJobs() {
242 return $this->mainQueue->getAllAcquiredJobs();
243 }
244
245 /**
246 * Get an iterator to traverse over all abandoned jobs in this queue
247 *
248 * @return Iterator
249 * @throws JobQueueError
250 * @since 1.25
251 */
252 public function getAllAbandonedJobs() {
253 return $this->mainQueue->getAllAbandonedJobs();
254 }
255
256 /**
257 * Do not use this function outside of JobQueue/JobQueueGroup
258 *
259 * @return string
260 * @since 1.22
261 */
262 public function getCoalesceLocationInternal() {
263 return $this->mainQueue->getCoalesceLocationInternal();
264 }
265
266 /**
267 * @see JobQueue::getSiblingQueuesWithJobs()
268 * @param array $types List of queues types
269 * @return array|null (list of queue types) or null if unsupported
270 */
271 protected function doGetSiblingQueuesWithJobs( array $types ) {
272 return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
273 }
274
275 /**
276 * @see JobQueue::getSiblingQueuesSize()
277 * @param array $types List of queues types
278 * @return array|null (list of queue types) or null if unsupported
279 */
280 protected function doGetSiblingQueueSizes( array $types ) {
281 return $this->mainQueue->doGetSiblingQueueSizes( $types );
282 }
283
284 /**
285 * @throws JobQueueReadOnlyError
286 */
287 protected function assertNotReadOnly() {
288 $this->mainQueue->assertNotReadOnly();
289 }
290 }