79 if ( !isset( self::$instances[
$domain] ) ) {
88 self::$instances[
$domain]->invalidWiki =
true;
92 return self::$instances[
$domain];
101 self::$instances = [];
120 if ( $this->readOnlyReason !==
false ) {
137 public function push( $jobs ) {
140 if ( $this->invalidWiki ) {
142 $e =
new LogicException(
"Domain '{$this->domain}' is not recognized." );
143 MWExceptionHandler::logException(
$e );
147 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
148 if ( !count( $jobs ) ) {
155 foreach ( $jobs as
$job ) {
156 $jobsByType[
$job->getType()][] =
$job;
159 foreach ( $jobsByType as
$type => $jobs ) {
163 if ( $this->
cache->has(
'queues-ready',
'list' ) ) {
164 $list = $this->
cache->get(
'queues-ready',
'list' );
165 if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
166 $this->
cache->clear(
'queues-ready' );
170 $cache = ObjectCache::getLocalClusterInstance();
172 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_ANY ),
178 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_DEFAULT ),
197 if ( $this->invalidWiki ) {
199 throw new LogicException(
"Domain '{$this->domain}' is not recognized." );
202 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' ) {
203 $this->
push( $jobs );
207 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
212 $this->bufferedJobs = array_merge( $this->bufferedJobs, $jobs );
222 foreach ( self::$instances as $group ) {
224 $group->push( $group->bufferedJobs );
225 $group->bufferedJobs = [];
226 }
catch ( Exception
$e ) {
228 MWExceptionHandler::logException(
$e );
244 public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = [] ) {
247 if ( is_string( $qtype ) ) {
248 if ( !in_array( $qtype, $blacklist ) ) {
249 $job = $this->
get( $qtype )->
pop();
252 if ( $flags & self::USE_CACHE ) {
253 if ( !$this->
cache->has(
'queues-ready',
'list', self::PROC_CACHE_TTL ) ) {
256 $types = $this->
cache->get(
'queues-ready',
'list' );
261 if ( $qtype == self::TYPE_DEFAULT ) {
265 $types = array_diff( $types, $blacklist );
268 foreach ( $types as
$type ) {
273 $this->
cache->clear(
'queues-ready' );
335 return array_diff( $this->
getQueueTypes(), $wgJobTypesExcludedFromDefaultQueue );
346 $cache = ObjectCache::getLocalClusterInstance();
347 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
352 if (
$type == self::TYPE_DEFAULT ) {
355 $value = count( $queues ) ?
'true' :
'false';
359 return (
$value ===
'true' );
370 $nonEmpty = $info[
'queue']->getSiblingQueuesWithJobs( $this->
getQueueTypes() );
371 if ( is_array( $nonEmpty ) ) {
372 $types = array_merge( $types, $nonEmpty );
374 foreach ( $info[
'types'] as
$type ) {
375 if ( !$this->
get( $type )->isEmpty() ) {
393 $sizes = $info[
'queue']->getSiblingQueueSizes( $this->
getQueueTypes() );
394 if ( is_array( $sizes ) ) {
395 $sizeMap = $sizeMap + $sizes;
397 foreach ( $info[
'types'] as
$type ) {
398 $sizeMap[
$type] = $this->
get(
$type )->getSize();
412 if ( $this->coalescedQueues ===
null ) {
413 $this->coalescedQueues = [];
416 [
'wiki' => $this->domain,
'type' =>
'null' ] + $conf );
417 $loc =
$queue->getCoalesceLocationInternal();
418 if ( !isset( $this->coalescedQueues[$loc] ) ) {
419 $this->coalescedQueues[$loc][
'queue'] =
$queue;
420 $this->coalescedQueues[$loc][
'types'] = [];
422 if (
$type ===
'default' ) {
423 $this->coalescedQueues[$loc][
'types'] = array_merge(
424 $this->coalescedQueues[$loc][
'types'],
428 $this->coalescedQueues[$loc][
'types'][] =
$type;
446 $cache = ObjectCache::getMainWANInstance();
448 $cache->makeGlobalKey(
'jobqueue',
'configvalue', $this->domain, $name ),
449 $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ),
450 function () use ( $wiki, $name ) {
453 return [
'v' =>
$wgConf->getConfig( $wiki, $name ) ];
455 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
466 foreach ( $jobs as
$job ) {
468 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );
474 $n = count( $this->bufferedJobs );
476 $type = implode(
', ', array_unique( array_map(
'get_class', $this->bufferedJobs ) ) );
477 trigger_error( __METHOD__ .
": $n buffered job(s) of type(s) $type never inserted." );
$wgJobTypeConf
Map of job types to configuration arrays.
$wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
$wgJobTypesExcludedFromDefaultQueue
Jobs that must be explicitly requested, i.e.
$wgConf
wgConf hold the site configuration.
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
Class to handle enqueueing of background jobs.
getCachedConfigVar( $name)
push( $jobs)
Insert jobs into the respective queues of which they belong.
string $domain
Wiki DB domain ID.
getQueueSizes()
Get the size of the queus for a list of job types.
ack(Job $job)
Acknowledge that a job was completed.
static pushLazyJobs()
Push all jobs buffered via lazyPush() into their respective queues.
waitForBackups()
Wait for any replica DBs or backup queue servers to catch up.
deduplicateRootJob(Job $job)
Register the "root job" of a given job into the queue for de-duplication.
array $coalescedQueues
Map of (bucket => (queue => JobQueue, types => list of types)
static singleton( $domain=false)
bool $invalidWiki
Whether the wiki is not recognized in configuration.
string bool $readOnlyReason
Read only rationale (or false if r/w)
getDefaultQueueTypes()
Get the list of default queue types.
lazyPush( $jobs)
Buffer jobs for insertion via push() or call it now if in CLI mode.
pop( $qtype=self::TYPE_DEFAULT, $flags=0, array $blacklist=[])
Pop a job off one of the job queues.
static destroySingletons()
Destroy the singleton instances.
queuesHaveJobs( $type=self::TYPE_ANY)
Check if there are any queues with jobs (this is cached)
__construct( $domain, $readOnlyReason)
static JobQueueGroup[] $instances
getQueuesWithJobs()
Get the list of job types that have non-empty queues.
assertValidJobs(array $jobs)
getQueueTypes()
Get the list of queue types.
static factory(array $params)
Get a job queue object of the specified type.
Class to both describe a background job and handle jobs.
Class for process caching individual properties of expiring items.
get( $key, $prop)
Get a property field for a cache entry.
set( $key, $prop, $value)
Set a property field for a cache entry.
static getCurrentWikiDbDomain()
static getWikiIdFromDomain( $domain)
Get the wiki ID of a database domain.
static isCurrentWikiDbDomain( $domain)
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
Job queue task description interface.
you have access to all of the normal MediaWiki so you can get a DB use the cache
if(count( $args)< 1) $job