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
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
18 class JobQueueSecondTestQueue
extends JobQueue
{
33 private $onlyWriteToDebugQueue;
35 protected function __construct( array $params ) {
36 if ( !isset( $params['mainqueue'] ) ) {
37 throw new MWException( "mainqueue parameter must be provided to the debug queue" );
40 if ( !isset( $params['debugqueue'] ) ) {
41 throw new MWException( "debugqueue parameter must be provided to the debug queue" );
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;
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 );
55 * Get the allowed queue orders for configuration validation
57 * @return array Subset of (random, timestamp, fifo, undefined)
59 protected function supportedOrders() {
60 return $this->mainQueue
->supportedOrders();
64 * Get the default queue order to use if configuration does not specify one
66 * @return string One of (random, timestamp, fifo, undefined)
68 protected function optimalOrder() {
69 return $this->mainQueue
->optimalOrder();
73 * Find out if delayed jobs are supported for configuration validation
75 * @return bool Whether delayed jobs are supported
77 protected function supportsDelayedJobs() {
78 return $this->mainQueue
->supportsDelayedJobs();
82 * @see JobQueue::isEmpty()
85 protected function doIsEmpty() {
86 return $this->mainQueue
->doIsEmpty();
90 * @see JobQueue::getSize()
93 protected function doGetSize() {
94 return $this->mainQueue
->doGetSize();
98 * @see JobQueue::getAcquiredCount()
101 protected function doGetAcquiredCount() {
102 return $this->mainQueue
->doGetAcquiredCount();
106 * @see JobQueue::getDelayedCount()
109 protected function doGetDelayedCount() {
110 return $this->mainQueue
->doGetDelayedCount();
114 * @see JobQueue::getAbandonedCount()
117 protected function doGetAbandonedCount() {
118 return $this->mainQueue
->doGetAbandonedCount();
122 * @see JobQueue::batchPush()
123 * @param IJobSpecification[] $jobs
126 protected function doBatchPush( array $jobs, $flags ) {
127 if ( !$this->onlyWriteToDebugQueue
) {
128 $this->mainQueue
->doBatchPush( $jobs, $flags );
132 $this->debugQueue
->doBatchPush( $jobs, $flags );
133 } catch ( Exception
$exception ) {
134 MWExceptionHandler
::logException( $exception );
139 * @see JobQueue::pop()
142 protected function doPop() {
143 return $this->mainQueue
->doPop();
147 * @see JobQueue::ack()
151 protected function doAck( Job
$job ) {
152 return $this->mainQueue
->doAck( $job );
156 * @see JobQueue::deduplicateRootJob()
157 * @param IJobSpecification $job
158 * @throws MWException
161 protected function doDeduplicateRootJob( IJobSpecification
$job ) {
162 return $this->mainQueue
->doDeduplicateRootJob( $job );
166 * @see JobQueue::isRootJobOldDuplicate()
170 protected function doIsRootJobOldDuplicate( Job
$job ) {
171 return $this->mainQueue
->doIsRootJobOldDuplicate( $job );
175 * @param string $signature Hash identifier of the root job
178 protected function getRootJobCacheKey( $signature ) {
179 return $this->mainQueue
->getRootJobCacheKey( $signature );
183 * @see JobQueue::delete()
185 * @throws MWException
187 protected function doDelete() {
188 return $this->mainQueue
->doDelete();
192 * @see JobQueue::waitForBackups()
195 protected function doWaitForBackups() {
196 $this->mainQueue
->doWaitForBackups();
200 * @see JobQueue::flushCaches()
203 protected function doFlushCaches() {
204 $this->mainQueue
->doFlushCaches();
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.
213 * @throws JobQueueError
215 public function getAllQueuedJobs() {
216 return $this->mainQueue
->getAllQueuedJobs();
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.
224 * @throws JobQueueError
227 public function getAllDelayedJobs() {
228 return $this->mainQueue
->getAllDelayedJobs();
232 * Get an iterator to traverse over all claimed jobs in this queue
234 * Callers should be quick to iterator over it or few results
235 * will be returned due to jobs being acknowledged and deleted
238 * @throws JobQueueError
241 public function getAllAcquiredJobs() {
242 return $this->mainQueue
->getAllAcquiredJobs();
246 * Get an iterator to traverse over all abandoned jobs in this queue
249 * @throws JobQueueError
252 public function getAllAbandonedJobs() {
253 return $this->mainQueue
->getAllAbandonedJobs();
257 * Do not use this function outside of JobQueue/JobQueueGroup
262 public function getCoalesceLocationInternal() {
263 return $this->mainQueue
->getCoalesceLocationInternal();
267 * @see JobQueue::getSiblingQueuesWithJobs()
268 * @param array $types List of queues types
269 * @return array|null (list of queue types) or null if unsupported
271 protected function doGetSiblingQueuesWithJobs( array $types ) {
272 return $this->mainQueue
->doGetSiblingQueuesWithJobs( $types );
276 * @see JobQueue::getSiblingQueuesSize()
277 * @param array $types List of queues types
278 * @return array|null (list of queue types) or null if unsupported
280 protected function doGetSiblingQueueSizes( array $types ) {
281 return $this->mainQueue
->doGetSiblingQueueSizes( $types );
285 * @throws JobQueueReadOnlyError
287 protected function assertNotReadOnly() {
288 $this->mainQueue
->assertNotReadOnly();