MediaWiki REL1_33
JobQueueMemory.php
Go to the documentation of this file.
1<?php
31class JobQueueMemory extends JobQueue {
33 protected static $data = [];
34
35 public function __construct( array $params ) {
36 parent::__construct( $params );
37
38 $this->dupCache = new HashBagOStuff();
39 }
40
47 protected function doBatchPush( array $jobs, $flags ) {
48 $unclaimed =& $this->getQueueData( 'unclaimed', [] );
49
50 foreach ( $jobs as $job ) {
51 if ( $job->ignoreDuplicates() ) {
52 $sha1 = sha1( serialize( $job->getDeduplicationInfo() ) );
53 if ( !isset( $unclaimed[$sha1] ) ) {
54 $unclaimed[$sha1] = $job;
55 }
56 } else {
57 $unclaimed[] = $job;
58 }
59 }
60 }
61
67 protected function supportedOrders() {
68 return [ 'random', 'timestamp', 'fifo' ];
69 }
70
76 protected function optimalOrder() {
77 return 'fifo';
78 }
79
85 protected function doIsEmpty() {
86 return ( $this->doGetSize() == 0 );
87 }
88
94 protected function doGetSize() {
95 $unclaimed = $this->getQueueData( 'unclaimed' );
96
97 return $unclaimed ? count( $unclaimed ) : 0;
98 }
99
105 protected function doGetAcquiredCount() {
106 $claimed = $this->getQueueData( 'claimed' );
107
108 return $claimed ? count( $claimed ) : 0;
109 }
110
116 protected function doPop() {
117 if ( $this->doGetSize() == 0 ) {
118 return false;
119 }
120
121 $unclaimed =& $this->getQueueData( 'unclaimed' );
122 $claimed =& $this->getQueueData( 'claimed', [] );
123
124 if ( $this->order === 'random' ) {
125 $key = array_rand( $unclaimed );
126 } else {
127 reset( $unclaimed );
128 $key = key( $unclaimed );
129 }
130
131 $spec = $unclaimed[$key];
132 unset( $unclaimed[$key] );
133 $claimed[] = $spec;
134
135 $job = $this->jobFromSpecInternal( $spec );
136
137 end( $claimed );
138 $job->setMetadata( 'claimId', key( $claimed ) );
139
140 return $job;
141 }
142
148 protected function doAck( Job $job ) {
149 if ( $this->getAcquiredCount() == 0 ) {
150 return;
151 }
152
153 $claimed =& $this->getQueueData( 'claimed' );
154 unset( $claimed[$job->getMetadata( 'claimId' )] );
155 }
156
160 protected function doDelete() {
161 if ( isset( self::$data[$this->type][$this->domain] ) ) {
162 unset( self::$data[$this->type][$this->domain] );
163 if ( !self::$data[$this->type] ) {
164 unset( self::$data[$this->type] );
165 }
166 }
167 }
168
174 public function getAllQueuedJobs() {
175 $unclaimed = $this->getQueueData( 'unclaimed' );
176 if ( !$unclaimed ) {
177 return new ArrayIterator( [] );
178 }
179
180 return new MappedIterator(
181 $unclaimed,
182 function ( $value ) {
183 return $this->jobFromSpecInternal( $value );
184 }
185 );
186 }
187
193 public function getAllAcquiredJobs() {
194 $claimed = $this->getQueueData( 'claimed' );
195 if ( !$claimed ) {
196 return new ArrayIterator( [] );
197 }
198
199 return new MappedIterator(
200 $claimed,
201 function ( $value ) {
202 return $this->jobFromSpecInternal( $value );
203 }
204 );
205 }
206
212 public function jobFromSpecInternal( IJobSpecification $spec ) {
213 return Job::factory( $spec->getType(), $spec->getTitle(), $spec->getParams() );
214 }
215
222 private function &getQueueData( $field, $init = null ) {
223 if ( !isset( self::$data[$this->type][$this->domain][$field] ) ) {
224 if ( $init !== null ) {
225 self::$data[$this->type][$this->domain][$field] = $init;
226 } else {
227 return $init;
228 }
229 }
230
231 return self::$data[$this->type][$this->domain][$field];
232 }
233}
serialize()
Simple store for keeping values in an associative array for the current process.
Class to handle job queues stored in PHP memory for testing.
__construct(array $params)
& getQueueData( $field, $init=null)
doBatchPush(array $jobs, $flags)
static array[] $data
jobFromSpecInternal(IJobSpecification $spec)
Class to handle enqueueing and running of background jobs.
Definition JobQueue.php:31
string $type
Job type.
Definition JobQueue.php:35
getAcquiredCount()
Get the number of acquired jobs (these are temporarily out of the queue).
Definition JobQueue.php:241
string $domain
DB domain ID.
Definition JobQueue.php:33
Class to both describe a background job and handle jobs.
Definition Job.php:30
static factory( $command, $params=[])
Create the appropriate object to handle a specific job.
Definition Job.php:72
Convenience class for generating iterators from iterators.
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
Definition hooks.txt:2163
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
Definition injection.txt:37
Job queue task description interface.
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))
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:30
if(count( $args)< 1) $job
$params