]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/jobqueue/JobQueueSecondTestQueue.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.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          * @return Job|bool
142          */
143         protected function doAck( Job $job ) {
144                 return $this->mainQueue->doAck( $job );
145         }
146
147         /**
148          * @see JobQueue::deduplicateRootJob()
149          * @param IJobSpecification $job
150          * @throws MWException
151          * @return bool
152          */
153         protected function doDeduplicateRootJob( IJobSpecification $job ) {
154                 return $this->mainQueue->doDeduplicateRootJob( $job );
155         }
156
157         /**
158          * @see JobQueue::isRootJobOldDuplicate()
159          * @param Job $job
160          * @return bool
161          */
162         protected function doIsRootJobOldDuplicate( Job $job ) {
163                 return $this->mainQueue->doIsRootJobOldDuplicate( $job );
164         }
165
166         /**
167          * @param string $signature Hash identifier of the root job
168          * @return string
169          */
170         protected function getRootJobCacheKey( $signature ) {
171                 return $this->mainQueue->getRootJobCacheKey( $signature );
172         }
173
174         /**
175          * @see JobQueue::delete()
176          * @return bool
177          * @throws MWException
178          */
179         protected function doDelete() {
180                 return $this->mainQueue->doDelete();
181         }
182
183         /**
184          * @see JobQueue::waitForBackups()
185          * @return void
186          */
187         protected function doWaitForBackups() {
188                 $this->mainQueue->doWaitForBackups();
189         }
190
191         /**
192          * @see JobQueue::flushCaches()
193          * @return void
194          */
195         protected function doFlushCaches() {
196                 $this->mainQueue->doFlushCaches();
197         }
198
199         /**
200          * Get an iterator to traverse over all available jobs in this queue.
201          * This does not include jobs that are currently acquired or delayed.
202          * Note: results may be stale if the queue is concurrently modified.
203          *
204          * @return Iterator
205          * @throws JobQueueError
206          */
207         public function getAllQueuedJobs() {
208                 return $this->mainQueue->getAllQueuedJobs();
209         }
210
211         /**
212          * Get an iterator to traverse over all delayed jobs in this queue.
213          * Note: results may be stale if the queue is concurrently modified.
214          *
215          * @return Iterator
216          * @throws JobQueueError
217          * @since 1.22
218          */
219         public function getAllDelayedJobs() {
220                 return $this->mainQueue->getAllDelayedJobs();
221         }
222
223         /**
224          * Get an iterator to traverse over all claimed jobs in this queue
225          *
226          * Callers should be quick to iterator over it or few results
227          * will be returned due to jobs being acknowledged and deleted
228          *
229          * @return Iterator
230          * @throws JobQueueError
231          * @since 1.26
232          */
233         public function getAllAcquiredJobs() {
234                 return $this->mainQueue->getAllAcquiredJobs();
235         }
236
237         /**
238          * Get an iterator to traverse over all abandoned jobs in this queue
239          *
240          * @return Iterator
241          * @throws JobQueueError
242          * @since 1.25
243          */
244         public function getAllAbandonedJobs() {
245                 return $this->mainQueue->getAllAbandonedJobs();
246         }
247
248         /**
249          * Do not use this function outside of JobQueue/JobQueueGroup
250          *
251          * @return string
252          * @since 1.22
253          */
254         public function getCoalesceLocationInternal() {
255                 return $this->mainQueue->getCoalesceLocationInternal();
256         }
257
258         /**
259          * @see JobQueue::getSiblingQueuesWithJobs()
260          * @param array $types List of queues types
261          * @return array|null (list of queue types) or null if unsupported
262          */
263         protected function doGetSiblingQueuesWithJobs( array $types ) {
264                 return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
265         }
266
267         /**
268          * @see JobQueue::getSiblingQueuesSize()
269          * @param array $types List of queues types
270          * @return array|null (list of queue types) or null if unsupported
271          */
272         protected function doGetSiblingQueueSizes( array $types ) {
273                 return $this->mainQueue->doGetSiblingQueueSizes( $types );
274         }
275
276         /**
277          * @throws JobQueueReadOnlyError
278          */
279         protected function assertNotReadOnly() {
280                 $this->mainQueue->assertNotReadOnly();
281         }
282 }