13 parent::__construct(
$name, $data, $dataName );
15 $this->tablesUsed[] =
'job';
22 if ( $this->
getCliArg(
'use-jobqueue' ) ) {
24 if ( !isset( $wgJobTypeConf[
$name] ) ) {
25 throw new MWException(
"No \$wgJobTypeConf entry for '$name'." );
27 $baseConfig = $wgJobTypeConf[
$name];
29 $baseConfig = [
'class' =>
'JobQueueDB' ];
31 $baseConfig[
'type'] =
'null';
34 'queueRand' => [
'order' =>
'random',
'claimTTL' => 0 ],
35 'queueRandTTL' => [
'order' =>
'random',
'claimTTL' => 10 ],
36 'queueTimestamp' => [
'order' =>
'timestamp',
'claimTTL' => 0 ],
37 'queueTimestampTTL' => [
'order' =>
'timestamp',
'claimTTL' => 10 ],
38 'queueFifo' => [
'order' =>
'fifo',
'claimTTL' => 0 ],
39 'queueFifoTTL' => [
'order' =>
'fifo',
'claimTTL' => 10 ],
41 foreach ( $variants
as $q => $settings ) {
55 'queueRand',
'queueRandTTL',
'queueTimestamp',
'queueTimestampTTL',
56 'queueFifo',
'queueFifoTTL'
73 $this->markTestSkipped( $desc );
75 $this->assertEquals(
wfWikiID(),
$queue->getWiki(),
"Proper wiki ID ($desc)" );
85 $this->markTestSkipped( $desc );
87 $this->assertEquals(
'null',
$queue->getType(),
"Proper job type ($desc)" );
97 $this->markTestSkipped( $desc );
100 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
103 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
104 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
106 $this->assertNull(
$queue->push( $this->newJob() ),
"Push worked ($desc)" );
107 $this->assertNull(
$queue->batchPush( [ $this->newJob() ] ),
"Push worked ($desc)" );
109 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
112 $this->assertEquals( 2,
$queue->getSize(),
"Queue size is correct ($desc)" );
113 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
114 $jobs = iterator_to_array(
$queue->getAllQueuedJobs() );
115 $this->assertEquals( 2, count( $jobs ),
"Queue iterator size is correct ($desc)" );
118 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
121 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
125 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
129 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
130 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
134 $this->assertEquals( 2,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
141 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
147 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
149 $this->assertNull(
$queue->batchPush( [ $this->newJob(), $this->
newJob() ] ),
150 "Push worked ($desc)" );
151 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
155 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
156 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
166 $this->markTestSkipped( $desc );
169 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
172 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
173 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
179 "Push worked ($desc)" );
181 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
184 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
185 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
191 "Push worked ($desc)"
194 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
197 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
198 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
201 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
204 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
206 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
212 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
222 $this->markTestSkipped( $desc );
245 $this->markTestSkipped( $desc );
248 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
251 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
252 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
256 for ( $i = 0; $i < 5; ++$i ) {
257 $this->assertNull(
$queue->push( $this->newJob( 0, $root1 ) ),
"Push worked ($desc)" );
259 $queue->deduplicateRootJob( $this->
newJob( 0, $root1 ) );
262 # Add a second to UNIX epoch and format back to TS_MW
263 $root2_ts = strtotime( $root2[
'rootJobTimestamp'] );
267 $this->assertNotEquals( $root1[
'rootJobTimestamp'], $root2[
'rootJobTimestamp'],
268 "Root job signatures have different timestamps." );
269 for ( $i = 0; $i < 5; ++$i ) {
270 $this->assertNull(
$queue->push( $this->newJob( 0, $root2 ) ),
"Push worked ($desc)" );
272 $queue->deduplicateRootJob( $this->
newJob( 0, $root2 ) );
274 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
277 $this->assertEquals( 10,
$queue->getSize(),
"Queue size is correct ($desc)" );
278 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
293 $this->assertEquals( 10, count( $jobs ),
"Correct number of jobs popped ($desc)" );
294 $this->assertEquals( 5, $dupcount,
"Correct number of duplicate jobs popped ($desc)" );
304 $this->markTestSkipped( $desc );
307 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
310 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
311 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
313 for ( $i = 0; $i < 10; ++$i ) {
314 $this->assertNull(
$queue->push( $this->newJob( $i ) ),
"Push worked ($desc)" );
317 for ( $i = 0; $i < 10; ++$i ) {
319 $this->assertTrue(
$job instanceof
Job,
"Jobs popped from queue ($desc)" );
321 $this->assertEquals( $i,
$params[
'i'],
"Job popped from queue is FIFO ($desc)" );
325 $this->assertFalse(
$queue->pop(),
"Queue is not empty ($desc)" );
328 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
329 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
337 if ( !
$queue || !method_exists(
$queue,
'getServerQueuesWithJobs' ) ) {
338 $this->markTestSkipped();
341 $this->assertNotContains(
343 $queue->getServerQueuesWithJobs(),
344 "Null queue not in listing"
349 $this->assertContains(
351 $queue->getServerQueuesWithJobs(),
352 "Null queue in listing"
358 [
'queueRand',
false,
'Random queue without ack()' ],
359 [
'queueRandTTL',
true,
'Random queue with ack()' ],
360 [
'queueTimestamp',
false,
'Time ordered queue without ack()' ],
361 [
'queueTimestampTTL',
true,
'Time ordered queue with ack()' ],
362 [
'queueFifo',
false,
'FIFO ordered queue without ack()' ],
363 [
'queueFifoTTL',
true,
'FIFO ordered queue with ack()' ]
369 [
'queueFifo',
false,
'Ordered queue without ack()' ],
370 [
'queueFifoTTL',
true,
'Ordered queue with ack()' ]
374 function newJob( $i = 0, $rootJob = [] ) {
376 [
'lives' => 0,
'usleep' => 0,
'removeDuplicates' => 0,
'i' => $i ] + $rootJob );
381 [
'lives' => 0,
'usleep' => 0,
'removeDuplicates' => 1,
'i' => $i ] + $rootJob );
the array() calling protocol came about after MediaWiki 1.4rc1.
static newMainPage()
Create a new Title for the Main Page.
static provider_fifoQueueLists()
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
testQueueAggregateTable()
JobQueue.
testGetWiki($queue, $recycles, $desc)
provider_queueLists JobQueue::getWiki
Class to both describe a background job and handle jobs.
static newRootJobParams($key)
Get "root job" parameters for a task.
JobQueue medium Database.
when a variable name is used in a it is silently declared as a new local masking the global
newDedupedJob($i=0, $rootJob=[])
No-op job that does nothing.
wfRandomString($length=32)
Get a random string containing a number of pseudo-random hex characters.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
testRootDeduplication($queue, $recycles, $desc)
provider_queueLists JobQueue
testJobOrder($queue, $recycles, $desc)
provider_fifoQueueLists JobQueue
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
testBasicOperations($queue, $recycles, $desc)
provider_queueLists JobQueue
testBasicDeduplication($queue, $recycles, $desc)
provider_queueLists JobQueue
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static factory(array $params)
Get a job queue object of the specified type.
Degenerate job that does nothing, but can optionally replace itself in the queue and/or sleep for a b...
testDeduplicationWhileClaimed($queue, $recycles, $desc)
provider_queueLists JobQueue
__construct($name=null, array $data=[], $dataName= '')
testGetType($queue, $recycles, $desc)
provider_queueLists JobQueue::getType
newJob($i=0, $rootJob=[])
static provider_queueLists()
Allows to change the fields on the form that will be generated $name