MediaWiki REL1_28
JobQueueMemory.php
Go to the documentation of this file.
1<?php
32class JobQueueMemory extends JobQueue {
34 protected static $data = [];
35
42 protected function doBatchPush( array $jobs, $flags ) {
43 $unclaimed =& $this->getQueueData( 'unclaimed', [] );
44
45 foreach ( $jobs as $job ) {
46 if ( $job->ignoreDuplicates() ) {
47 $sha1 = Wikimedia\base_convert(
48 sha1( serialize( $job->getDeduplicationInfo() ) ),
49 16, 36, 31
50 );
51 if ( !isset( $unclaimed[$sha1] ) ) {
52 $unclaimed[$sha1] = $job;
53 }
54 } else {
55 $unclaimed[] = $job;
56 }
57 }
58 }
59
65 protected function supportedOrders() {
66 return [ 'random', 'timestamp', 'fifo' ];
67 }
68
74 protected function optimalOrder() {
75 return 'fifo';
76 }
77
83 protected function doIsEmpty() {
84 return ( $this->doGetSize() == 0 );
85 }
86
92 protected function doGetSize() {
93 $unclaimed = $this->getQueueData( 'unclaimed' );
94
95 return $unclaimed ? count( $unclaimed ) : 0;
96 }
97
103 protected function doGetAcquiredCount() {
104 $claimed = $this->getQueueData( 'claimed' );
105
106 return $claimed ? count( $claimed ) : 0;
107 }
108
114 protected function doPop() {
115 if ( $this->doGetSize() == 0 ) {
116 return false;
117 }
118
119 $unclaimed =& $this->getQueueData( 'unclaimed' );
120 $claimed =& $this->getQueueData( 'claimed', [] );
121
122 if ( $this->order === 'random' ) {
123 $key = array_rand( $unclaimed );
124 } else {
125 reset( $unclaimed );
126 $key = key( $unclaimed );
127 }
128
129 $spec = $unclaimed[$key];
130 unset( $unclaimed[$key] );
131 $claimed[] = $spec;
132
133 $job = $this->jobFromSpecInternal( $spec );
134
135 end( $claimed );
136 $job->metadata['claimId'] = key( $claimed );
137
138 return $job;
139 }
140
146 protected function doAck( Job $job ) {
147 if ( $this->getAcquiredCount() == 0 ) {
148 return;
149 }
150
151 $claimed =& $this->getQueueData( 'claimed' );
152 unset( $claimed[$job->metadata['claimId']] );
153 }
154
158 protected function doDelete() {
159 if ( isset( self::$data[$this->type][$this->wiki] ) ) {
160 unset( self::$data[$this->type][$this->wiki] );
161 if ( !self::$data[$this->type] ) {
162 unset( self::$data[$this->type] );
163 }
164 }
165 }
166
172 public function getAllQueuedJobs() {
173 $unclaimed = $this->getQueueData( 'unclaimed' );
174 if ( !$unclaimed ) {
175 return new ArrayIterator( [] );
176 }
177
178 return new MappedIterator(
179 $unclaimed,
180 function ( $value ) {
181 $this->jobFromSpecInternal( $value );
182 }
183 );
184 }
185
191 public function getAllAcquiredJobs() {
192 $claimed = $this->getQueueData( 'claimed' );
193 if ( !$claimed ) {
194 return new ArrayIterator( [] );
195 }
196
197 return new MappedIterator(
198 $claimed,
199 function ( $value ) {
200 $this->jobFromSpecInternal( $value );
201 }
202 );
203 }
204
210 public function jobFromSpecInternal( IJobSpecification $spec ) {
211 return Job::factory( $spec->getType(), $spec->getTitle(), $spec->getParams() );
212 }
213
220 private function &getQueueData( $field, $init = null ) {
221 if ( !isset( self::$data[$this->type][$this->wiki][$field] ) ) {
222 if ( $init !== null ) {
223 self::$data[$this->type][$this->wiki][$field] = $init;
224 } else {
225 return $init;
226 }
227 }
228
229 return self::$data[$this->type][$this->wiki][$field];
230 }
231}
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:2710
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