rdbms: Avoid selectDB() call in LoadMonitor new connections
[mediawiki.git] / includes / jobqueue / JobQueueSecondTestQueue.php
bloba1935dfa0ddab59fb8ddca176fe44a17f923b5c3
1 <?php
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.
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.
15 * @deprecated since 1.30
16 * @since 1.30
18 class JobQueueSecondTestQueue extends JobQueue {
20 /**
21 * @var JobQueue
23 private $mainQueue;
25 /**
26 * @var JobQueue
28 private $debugQueue;
30 protected function __construct( array $params ) {
31 if ( !isset( $params['mainqueue'] ) ) {
32 throw new MWException( "mainqueue parameter must be provided to the debug queue" );
35 if ( !isset( $params['debugqueue'] ) ) {
36 throw new MWException( "debugqueue parameter must be provided to the debug queue" );
39 $conf = [ 'wiki' => $params['wiki'], 'type' => $params['type'] ];
40 $this->mainQueue = JobQueue::factory( $params['mainqueue'] + $conf );
41 $this->debugQueue = JobQueue::factory( $params['debugqueue'] + $conf );
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 );
48 /**
49 * Get the allowed queue orders for configuration validation
51 * @return array Subset of (random, timestamp, fifo, undefined)
53 protected function supportedOrders() {
54 return $this->mainQueue->supportedOrders();
57 /**
58 * Get the default queue order to use if configuration does not specify one
60 * @return string One of (random, timestamp, fifo, undefined)
62 protected function optimalOrder() {
63 return $this->mainQueue->optimalOrder();
66 /**
67 * Find out if delayed jobs are supported for configuration validation
69 * @return bool Whether delayed jobs are supported
71 protected function supportsDelayedJobs() {
72 return $this->mainQueue->supportsDelayedJobs();
75 /**
76 * @see JobQueue::isEmpty()
77 * @return bool
79 protected function doIsEmpty() {
80 return $this->mainQueue->doIsEmpty();
83 /**
84 * @see JobQueue::getSize()
85 * @return int
87 protected function doGetSize() {
88 return $this->mainQueue->doGetSize();
91 /**
92 * @see JobQueue::getAcquiredCount()
93 * @return int
95 protected function doGetAcquiredCount() {
96 return $this->mainQueue->doGetAcquiredCount();
99 /**
100 * @see JobQueue::getDelayedCount()
101 * @return int
103 protected function doGetDelayedCount() {
104 return $this->mainQueue->doGetDelayedCount();
108 * @see JobQueue::getAbandonedCount()
109 * @return int
111 protected function doGetAbandonedCount() {
112 return $this->mainQueue->doGetAbandonedCount();
116 * @see JobQueue::batchPush()
117 * @param IJobSpecification[] $jobs
118 * @param int $flags
120 protected function doBatchPush( array $jobs, $flags ) {
121 $this->mainQueue->doBatchPush( $jobs, $flags );
123 try {
124 $this->debugQueue->doBatchPush( $jobs, $flags );
125 } catch ( Exception $exception ) {
126 MWExceptionHandler::logException( $exception );
131 * @see JobQueue::pop()
132 * @return Job|bool
134 protected function doPop() {
135 return $this->mainQueue->doPop();
139 * @see JobQueue::ack()
140 * @param Job $job
142 protected function doAck( Job $job ) {
143 return $this->mainQueue->doAck( $job );
147 * @see JobQueue::deduplicateRootJob()
148 * @param IJobSpecification $job
149 * @throws MWException
150 * @return bool
152 protected function doDeduplicateRootJob( IJobSpecification $job ) {
153 return $this->mainQueue->doDeduplicateRootJob( $job );
157 * @see JobQueue::isRootJobOldDuplicate()
158 * @param Job $job
159 * @return bool
161 protected function doIsRootJobOldDuplicate( Job $job ) {
162 return $this->mainQueue->doIsRootJobOldDuplicate( $job );
166 * @param string $signature Hash identifier of the root job
167 * @return string
169 protected function getRootJobCacheKey( $signature ) {
170 return $this->mainQueue->getRootJobCacheKey( $signature );
174 * @see JobQueue::delete()
175 * @throws MWException
177 protected function doDelete() {
178 return $this->mainQueue->doDelete();
182 * @see JobQueue::waitForBackups()
183 * @return void
185 protected function doWaitForBackups() {
186 $this->mainQueue->doWaitForBackups();
190 * @see JobQueue::flushCaches()
191 * @return void
193 protected function doFlushCaches() {
194 $this->mainQueue->doFlushCaches();
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.
202 * @return Iterator
203 * @throws JobQueueError
205 public function getAllQueuedJobs() {
206 return $this->mainQueue->getAllQueuedJobs();
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.
213 * @return Iterator
214 * @throws JobQueueError
215 * @since 1.22
217 public function getAllDelayedJobs() {
218 return $this->mainQueue->getAllDelayedJobs();
222 * Get an iterator to traverse over all claimed jobs in this queue
224 * Callers should be quick to iterator over it or few results
225 * will be returned due to jobs being acknowledged and deleted
227 * @return Iterator
228 * @throws JobQueueError
229 * @since 1.26
231 public function getAllAcquiredJobs() {
232 return $this->mainQueue->getAllAcquiredJobs();
236 * Get an iterator to traverse over all abandoned jobs in this queue
238 * @return Iterator
239 * @throws JobQueueError
240 * @since 1.25
242 public function getAllAbandonedJobs() {
243 return $this->mainQueue->getAllAbandonedJobs();
247 * Do not use this function outside of JobQueue/JobQueueGroup
249 * @return string
250 * @since 1.22
252 public function getCoalesceLocationInternal() {
253 return $this->mainQueue->getCoalesceLocationInternal();
257 * @see JobQueue::getSiblingQueuesWithJobs()
258 * @param array $types List of queues types
259 * @return array|null (list of queue types) or null if unsupported
261 protected function doGetSiblingQueuesWithJobs( array $types ) {
262 return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
266 * @see JobQueue::getSiblingQueuesSize()
267 * @param array $types List of queues types
268 * @return array|null (list of queue types) or null if unsupported
270 protected function doGetSiblingQueueSizes( array $types ) {
271 return $this->mainQueue->doGetSiblingQueueSizes( $types );
275 * @throws JobQueueReadOnlyError
277 protected function assertNotReadOnly() {
278 $this->mainQueue->assertNotReadOnly();