15 parent::__construct(
$name,
$data, $dataName );
17 $this->tablesUsed[] =
'job';
24 if ( $this->
getCliArg(
'use-jobqueue' ) ) {
27 throw new MWException(
"No \$wgJobTypeConf entry for '$name'." );
31 $baseConfig = [
'class' => JobQueueDBSingle::class ];
33 $baseConfig[
'type'] =
'null';
34 $baseConfig[
'domain'] = WikiMap::getCurrentWikiDbDomain()->getId();
38 'queueRand' => [
'order' =>
'random',
'claimTTL' => 0 ],
39 'queueRandTTL' => [
'order' =>
'random',
'claimTTL' => 10 ],
40 'queueTimestamp' => [
'order' =>
'timestamp',
'claimTTL' => 0 ],
41 'queueTimestampTTL' => [
'order' =>
'timestamp',
'claimTTL' => 10 ],
42 'queueFifo' => [
'order' =>
'fifo',
'claimTTL' => 0 ],
43 'queueFifoTTL' => [
'order' =>
'fifo',
'claimTTL' => 10 ],
45 foreach ( $variants
as $q => $settings ) {
59 'queueRand',
'queueRandTTL',
'queueTimestamp',
'queueTimestampTTL',
60 'queueFifo',
'queueFifoTTL'
77 $this->markTestSkipped( $desc );
79 $this->assertEquals(
wfWikiID(),
$queue->getWiki(),
"Proper wiki ID ($desc)" );
81 WikiMap::getCurrentWikiDbDomain()->getId(),
83 "Proper wiki ID ($desc)" );
93 $this->markTestSkipped( $desc );
95 $this->assertEquals(
'null',
$queue->getType(),
"Proper job type ($desc)" );
105 $this->markTestSkipped( $desc );
108 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
111 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
112 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
114 $this->assertNull(
$queue->push( $this->newJob() ),
"Push worked ($desc)" );
115 $this->assertNull(
$queue->batchPush( [ $this->newJob() ] ),
"Push worked ($desc)" );
117 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
120 $this->assertEquals( 2,
$queue->getSize(),
"Queue size is correct ($desc)" );
121 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
122 $jobs = iterator_to_array(
$queue->getAllQueuedJobs() );
123 $this->assertEquals( 2, count( $jobs ),
"Queue iterator size is correct ($desc)" );
126 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
129 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
133 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
137 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
138 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
142 $this->assertEquals( 2,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
149 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
155 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
157 $this->assertNull(
$queue->batchPush( [ $this->newJob(), $this->newJob() ] ),
158 "Push worked ($desc)" );
159 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
163 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
164 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
174 $this->markTestSkipped( $desc );
177 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
180 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
181 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
185 [ $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ]
187 "Push worked ($desc)" );
189 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
192 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
193 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
197 [ $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ]
199 "Push worked ($desc)"
202 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
205 $this->assertEquals( 1,
$queue->getSize(),
"Queue size is correct ($desc)" );
206 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
209 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
212 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
214 $this->assertEquals( 1,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
220 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Active job count ($desc)" );
230 $this->markTestSkipped( $desc );
253 $this->markTestSkipped( $desc );
256 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
259 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
260 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
264 for ( $i = 0; $i < 5; ++$i ) {
265 $this->assertNull(
$queue->push( $this->newJob( 0, $root1 ) ),
"Push worked ($desc)" );
267 $queue->deduplicateRootJob( $this->
newJob( 0, $root1 ) );
270 # Add a second to UNIX epoch and format back to TS_MW
271 $root2_ts = strtotime( $root2[
'rootJobTimestamp'] );
273 $root2[
'rootJobTimestamp'] =
wfTimestamp( TS_MW, $root2_ts );
275 $this->assertNotEquals( $root1[
'rootJobTimestamp'], $root2[
'rootJobTimestamp'],
276 "Root job signatures have different timestamps." );
277 for ( $i = 0; $i < 5; ++$i ) {
278 $this->assertNull(
$queue->push( $this->newJob( 0, $root2 ) ),
"Push worked ($desc)" );
280 $queue->deduplicateRootJob( $this->
newJob( 0, $root2 ) );
282 $this->assertFalse(
$queue->isEmpty(),
"Queue is not empty ($desc)" );
285 $this->assertEquals( 10,
$queue->getSize(),
"Queue size is correct ($desc)" );
286 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
301 $this->assertEquals( 10, count( $jobs ),
"Correct number of jobs popped ($desc)" );
302 $this->assertEquals( 5, $dupcount,
"Correct number of duplicate jobs popped ($desc)" );
312 $this->markTestSkipped( $desc );
315 $this->assertTrue(
$queue->isEmpty(),
"Queue is empty ($desc)" );
318 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
319 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"Queue is empty ($desc)" );
321 for ( $i = 0; $i < 10; ++$i ) {
322 $this->assertNull(
$queue->push( $this->newJob( $i ) ),
"Push worked ($desc)" );
325 for ( $i = 0; $i < 10; ++$i ) {
327 $this->assertTrue(
$job instanceof
Job,
"Jobs popped from queue ($desc)" );
329 $this->assertEquals( $i,
$params[
'i'],
"Job popped from queue is FIFO ($desc)" );
333 $this->assertFalse(
$queue->pop(),
"Queue is not empty ($desc)" );
336 $this->assertEquals( 0,
$queue->getSize(),
"Queue is empty ($desc)" );
337 $this->assertEquals( 0,
$queue->getAcquiredCount(),
"No jobs active ($desc)" );
345 if ( !
$queue || !method_exists(
$queue,
'getServerQueuesWithJobs' ) ) {
346 $this->markTestSkipped();
349 $this->assertNotContains(
351 $queue->getServerQueuesWithJobs(),
352 "Null queue not in listing"
357 $this->assertContains(
359 $queue->getServerQueuesWithJobs(),
360 "Null queue in listing"
366 [
'queueRand',
false,
'Random queue without ack()' ],
367 [
'queueRandTTL',
true,
'Random queue with ack()' ],
368 [
'queueTimestamp',
false,
'Time ordered queue without ack()' ],
369 [
'queueTimestampTTL',
true,
'Time ordered queue with ack()' ],
370 [
'queueFifo',
false,
'FIFO ordered queue without ack()' ],
371 [
'queueFifoTTL',
true,
'FIFO ordered queue with ack()' ]
377 [
'queueFifo',
false,
'Ordered queue without ack()' ],
378 [
'queueFifoTTL',
true,
'Ordered queue with ack()' ]
382 function newJob( $i = 0, $rootJob = [] ) {
383 return new NullJob( Title::newMainPage(),
384 [
'lives' => 0,
'usleep' => 0,
'removeDuplicates' => 0,
'i' => $i ] + $rootJob );
388 return new NullJob( Title::newMainPage(),
389 [
'lives' => 0,
'usleep' => 0,
'removeDuplicates' => 1,
'i' => $i ] + $rootJob );
394 protected function getDB( $index ) {
395 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
397 return $lb->getConnection( $index, [], $this->domain );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgJobTypeConf
Map of job types to configuration arrays.
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.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
No-op job that does nothing.
Simple store for keeping values in an associative array for the current process.
Class to handle job queues stored in the DB.
JobQueue medium Database.
testBasicOperations( $queue, $recycles, $desc)
provider_queueLists JobQueue
testJobOrder( $queue, $recycles, $desc)
provider_fifoQueueLists JobQueue
testRootDeduplication( $queue, $recycles, $desc)
provider_queueLists JobQueue
static provider_queueLists()
__construct( $name=null, array $data=[], $dataName='')
static provider_fifoQueueLists()
testBasicDeduplication( $queue, $recycles, $desc)
provider_queueLists JobQueue
testDeduplicationWhileClaimed( $queue, $recycles, $desc)
provider_queueLists JobQueue
newJob( $i=0, $rootJob=[])
testQueueAggregateTable()
JobQueue.
testGetWiki( $queue, $recycles, $desc)
provider_queueLists JobQueue::getWiki
testGetType( $queue, $recycles, $desc)
provider_queueLists JobQueue::getType
newDedupedJob( $i=0, $rootJob=[])
static factory(array $params)
Get a job queue object of the specified type.
Class to both describe a background job and handle jobs.
static newRootJobParams( $key)
Get "root job" parameters for a task.
Degenerate job that does nothing, but can optionally replace itself in the queue and/or sleep for a b...
Multi-datacenter aware caching interface.
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(count( $args)< 1) $job