summaryrefslogtreecommitdiff
path: root/www/wiki/includes/jobqueue/JobQueueSecondTestQueue.php
blob: 01f467f20b4e75e14177486f4b6b933f879cf0e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php

/**
 * A wrapper for the JobQueue that delegates all the method calls to a single,
 * main queue, and also pushes all the jobs to a second job queue that's being
 * debugged.
 *
 * This class was temporary added to test transitioning to the JobQueueEventBus
 * and will removed after the transition is completed. This code is only needed
 * while we are testing the new infrastructure to be able to compare the results
 * between the queue implementations and make sure that they process the same jobs,
 * deduplicate correctly, compare the delays, backlogs and make sure no jobs are lost.
 * When the new infrastructure is well tested this will not be needed any more.
 *
 * @deprecated since 1.30
 * @since 1.30
 */
class JobQueueSecondTestQueue extends JobQueue {

	/**
	 * @var JobQueue
	 */
	private $mainQueue;

	/**
	 * @var JobQueue
	 */
	private $debugQueue;

	/**
	 * @var bool
	 */
	private $onlyWriteToDebugQueue;

	protected function __construct( array $params ) {
		if ( !isset( $params['mainqueue'] ) ) {
			throw new MWException( "mainqueue parameter must be provided to the debug queue" );
		}

		if ( !isset( $params['debugqueue'] ) ) {
			throw new MWException( "debugqueue parameter must be provided to the debug queue" );
		}

		$conf = [ 'wiki' => $params['wiki'], 'type' => $params['type'] ];
		$this->mainQueue = JobQueue::factory( $params['mainqueue'] + $conf );
		$this->debugQueue = JobQueue::factory( $params['debugqueue'] + $conf );
		$this->onlyWriteToDebugQueue = isset( $params['readonly'] ) ? $params['readonly'] : false;

		// We need to construct parent after creating the main and debug queue
		// because super constructor calls some methods we delegate to the main queue.
		parent::__construct( $params );
	}

	/**
	 * Get the allowed queue orders for configuration validation
	 *
	 * @return array Subset of (random, timestamp, fifo, undefined)
	 */
	protected function supportedOrders() {
		return $this->mainQueue->supportedOrders();
	}

	/**
	 * Get the default queue order to use if configuration does not specify one
	 *
	 * @return string One of (random, timestamp, fifo, undefined)
	 */
	protected function optimalOrder() {
		return $this->mainQueue->optimalOrder();
	}

	/**
	 * Find out if delayed jobs are supported for configuration validation
	 *
	 * @return bool Whether delayed jobs are supported
	 */
	protected function supportsDelayedJobs() {
		return $this->mainQueue->supportsDelayedJobs();
	}

	/**
	 * @see JobQueue::isEmpty()
	 * @return bool
	 */
	protected function doIsEmpty() {
		return $this->mainQueue->doIsEmpty();
	}

	/**
	 * @see JobQueue::getSize()
	 * @return int
	 */
	protected function doGetSize() {
		return $this->mainQueue->doGetSize();
	}

	/**
	 * @see JobQueue::getAcquiredCount()
	 * @return int
	 */
	protected function doGetAcquiredCount() {
		return $this->mainQueue->doGetAcquiredCount();
	}

	/**
	 * @see JobQueue::getDelayedCount()
	 * @return int
	 */
	protected function doGetDelayedCount() {
		return $this->mainQueue->doGetDelayedCount();
	}

	/**
	 * @see JobQueue::getAbandonedCount()
	 * @return int
	 */
	protected function doGetAbandonedCount() {
		return $this->mainQueue->doGetAbandonedCount();
	}

	/**
	 * @see JobQueue::batchPush()
	 * @param IJobSpecification[] $jobs
	 * @param int $flags
	 */
	protected function doBatchPush( array $jobs, $flags ) {
		if ( !$this->onlyWriteToDebugQueue ) {
			$this->mainQueue->doBatchPush( $jobs, $flags );
		}

		try {
			$this->debugQueue->doBatchPush( $jobs, $flags );
		} catch ( Exception $exception ) {
			MWExceptionHandler::logException( $exception );
		}
	}

	/**
	 * @see JobQueue::pop()
	 * @return Job|bool
	 */
	protected function doPop() {
		return $this->mainQueue->doPop();
	}

	/**
	 * @see JobQueue::ack()
	 * @param Job $job
	 * @return Job|bool
	 */
	protected function doAck( Job $job ) {
		return $this->mainQueue->doAck( $job );
	}

	/**
	 * @see JobQueue::deduplicateRootJob()
	 * @param IJobSpecification $job
	 * @throws MWException
	 * @return bool
	 */
	protected function doDeduplicateRootJob( IJobSpecification $job ) {
		return $this->mainQueue->doDeduplicateRootJob( $job );
	}

	/**
	 * @see JobQueue::isRootJobOldDuplicate()
	 * @param Job $job
	 * @return bool
	 */
	protected function doIsRootJobOldDuplicate( Job $job ) {
		return $this->mainQueue->doIsRootJobOldDuplicate( $job );
	}

	/**
	 * @param string $signature Hash identifier of the root job
	 * @return string
	 */
	protected function getRootJobCacheKey( $signature ) {
		return $this->mainQueue->getRootJobCacheKey( $signature );
	}

	/**
	 * @see JobQueue::delete()
	 * @return bool
	 * @throws MWException
	 */
	protected function doDelete() {
		return $this->mainQueue->doDelete();
	}

	/**
	 * @see JobQueue::waitForBackups()
	 * @return void
	 */
	protected function doWaitForBackups() {
		$this->mainQueue->doWaitForBackups();
	}

	/**
	 * @see JobQueue::flushCaches()
	 * @return void
	 */
	protected function doFlushCaches() {
		$this->mainQueue->doFlushCaches();
	}

	/**
	 * Get an iterator to traverse over all available jobs in this queue.
	 * This does not include jobs that are currently acquired or delayed.
	 * Note: results may be stale if the queue is concurrently modified.
	 *
	 * @return Iterator
	 * @throws JobQueueError
	 */
	public function getAllQueuedJobs() {
		return $this->mainQueue->getAllQueuedJobs();
	}

	/**
	 * Get an iterator to traverse over all delayed jobs in this queue.
	 * Note: results may be stale if the queue is concurrently modified.
	 *
	 * @return Iterator
	 * @throws JobQueueError
	 * @since 1.22
	 */
	public function getAllDelayedJobs() {
		return $this->mainQueue->getAllDelayedJobs();
	}

	/**
	 * Get an iterator to traverse over all claimed jobs in this queue
	 *
	 * Callers should be quick to iterator over it or few results
	 * will be returned due to jobs being acknowledged and deleted
	 *
	 * @return Iterator
	 * @throws JobQueueError
	 * @since 1.26
	 */
	public function getAllAcquiredJobs() {
		return $this->mainQueue->getAllAcquiredJobs();
	}

	/**
	 * Get an iterator to traverse over all abandoned jobs in this queue
	 *
	 * @return Iterator
	 * @throws JobQueueError
	 * @since 1.25
	 */
	public function getAllAbandonedJobs() {
		return $this->mainQueue->getAllAbandonedJobs();
	}

	/**
	 * Do not use this function outside of JobQueue/JobQueueGroup
	 *
	 * @return string
	 * @since 1.22
	 */
	public function getCoalesceLocationInternal() {
		return $this->mainQueue->getCoalesceLocationInternal();
	}

	/**
	 * @see JobQueue::getSiblingQueuesWithJobs()
	 * @param array $types List of queues types
	 * @return array|null (list of queue types) or null if unsupported
	 */
	protected function doGetSiblingQueuesWithJobs( array $types ) {
		return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
	}

	/**
	 * @see JobQueue::getSiblingQueuesSize()
	 * @param array $types List of queues types
	 * @return array|null (list of queue types) or null if unsupported
	 */
	protected function doGetSiblingQueueSizes( array $types ) {
		return $this->mainQueue->doGetSiblingQueueSizes( $types );
	}

	/**
	 * @throws JobQueueReadOnlyError
	 */
	protected function assertNotReadOnly() {
		$this->mainQueue->assertNotReadOnly();
	}
}