MediaWiki REL1_30
JobQueueMemory.php
Go to the documentation of this file.
1<?php
31class JobQueueMemory extends JobQueue {
33 protected static $data = [];
34
41 protected function doBatchPush( array $jobs, $flags ) {
42 $unclaimed =& $this->getQueueData( 'unclaimed', [] );
43
44 foreach ( $jobs as $job ) {
45 if ( $job->ignoreDuplicates() ) {
46 $sha1 = Wikimedia\base_convert(
47 sha1( serialize( $job->getDeduplicationInfo() ) ),
48 16, 36, 31
49 );
50 if ( !isset( $unclaimed[$sha1] ) ) {
51 $unclaimed[$sha1] = $job;
52 }
53 } else {
54 $unclaimed[] = $job;
55 }
56 }
57 }
58
64 protected function supportedOrders() {
65 return [ 'random', 'timestamp', 'fifo' ];
66 }
67
73 protected function optimalOrder() {
74 return 'fifo';
75 }
76
82 protected function doIsEmpty() {
83 return ( $this->doGetSize() == 0 );
84 }
85
91 protected function doGetSize() {
92 $unclaimed = $this->getQueueData( 'unclaimed' );
93
94 return $unclaimed ? count( $unclaimed ) : 0;
95 }
96
102 protected function doGetAcquiredCount() {
103 $claimed = $this->getQueueData( 'claimed' );
104
105 return $claimed ? count( $claimed ) : 0;
106 }
107
113 protected function doPop() {
114 if ( $this->doGetSize() == 0 ) {
115 return false;
116 }
117
118 $unclaimed =& $this->getQueueData( 'unclaimed' );
119 $claimed =& $this->getQueueData( 'claimed', [] );
120
121 if ( $this->order === 'random' ) {
122 $key = array_rand( $unclaimed );
123 } else {
124 reset( $unclaimed );
125 $key = key( $unclaimed );
126 }
127
128 $spec = $unclaimed[$key];
129 unset( $unclaimed[$key] );
130 $claimed[] = $spec;
131
132 $job = $this->jobFromSpecInternal( $spec );
133
134 end( $claimed );
135 $job->metadata['claimId'] = key( $claimed );
136
137 return $job;
138 }
139
145 protected function doAck( Job $job ) {
146 if ( $this->getAcquiredCount() == 0 ) {
147 return;
148 }
149
150 $claimed =& $this->getQueueData( 'claimed' );
151 unset( $claimed[$job->metadata['claimId']] );
152 }
153
157 protected function doDelete() {
158 if ( isset( self::$data[$this->type][$this->wiki] ) ) {
159 unset( self::$data[$this->type][$this->wiki] );
160 if ( !self::$data[$this->type] ) {
161 unset( self::$data[$this->type] );
162 }
163 }
164 }
165
171 public function getAllQueuedJobs() {
172 $unclaimed = $this->getQueueData( 'unclaimed' );
173 if ( !$unclaimed ) {
174 return new ArrayIterator( [] );
175 }
176
177 return new MappedIterator(
178 $unclaimed,
179 function ( $value ) {
180 return $this->jobFromSpecInternal( $value );
181 }
182 );
183 }
184
190 public function getAllAcquiredJobs() {
191 $claimed = $this->getQueueData( 'claimed' );
192 if ( !$claimed ) {
193 return new ArrayIterator( [] );
194 }
195
196 return new MappedIterator(
197 $claimed,
198 function ( $value ) {
199 return $this->jobFromSpecInternal( $value );
200 }
201 );
202 }
203
209 public function jobFromSpecInternal( IJobSpecification $spec ) {
210 return Job::factory( $spec->getType(), $spec->getTitle(), $spec->getParams() );
211 }
212
219 private function &getQueueData( $field, $init = null ) {
220 if ( !isset( self::$data[$this->type][$this->wiki][$field] ) ) {
221 if ( $init !== null ) {
222 self::$data[$this->type][$this->wiki][$field] = $init;
223 } else {
224 return $init;
225 }
226 }
227
228 return self::$data[$this->type][$this->wiki][$field];
229 }
230}
serialize()
Class to handle job queues stored in PHP memory for testing.
& 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
string $wiki
Wiki ID.
Definition JobQueue.php:33
getAcquiredCount()
Get the number of acquired jobs (these are temporarily out of the queue).
Definition JobQueue.php:235
Class to both describe a background job and handle jobs.
Definition Job.php:31
static factory( $command, Title $title, $params=[])
Create the appropriate object to handle a specific job.
Definition Job.php:68
Convenience class for generating iterators from iterators.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition design.txt:26
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any order
Definition design.txt:19
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
the array() calling protocol came about after MediaWiki 1.4rc1.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2805
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.
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
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 as and are nearing end of 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:36
if(count( $args)< 1) $job