MediaWiki REL1_31
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:74
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
Job queue task description interface.
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