70 public static function singleton( $domain =
false ) {
74 $domain = WikiMap::getCurrentWikiDbDomain()->getId();
77 if ( !isset( self::$instances[
$domain] ) ) {
81 $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
83 !WikiMap::isCurrentWikiDbDomain( $domain ) &&
86 self::$instances[$domain]->invalidDomain =
true;
90 return self::$instances[$domain];
99 self::$instances = [];
111 $conf = [
'domain' => $this->domain,
'type' =>
$type ];
117 if ( !isset( $conf[
'readOnlyReason'] ) ) {
118 $conf[
'readOnlyReason'] = $this->readOnlyReason;
121 $services = MediaWikiServices::getInstance();
122 $conf[
'stats'] =
$services->getStatsdDataFactory();
123 $conf[
'wanCache'] =
$services->getMainWANObjectCache();
124 $conf[
'stash'] =
$services->getMainObjectStash();
139 public function push( $jobs ) {
142 if ( $this->invalidDomain ) {
144 $e =
new LogicException(
"Domain '{$this->domain}' is not recognized." );
145 MWExceptionHandler::logException(
$e );
149 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
150 if ( $jobs === [] ) {
157 foreach ( $jobs
as $job ) {
158 $jobsByType[
$job->getType()][] =
$job;
161 foreach ( $jobsByType
as $type => $jobs ) {
165 if ( $this->
cache->hasField(
'queues-ready',
'list' ) ) {
166 $list = $this->
cache->getField(
'queues-ready',
'list' );
167 if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
168 $this->
cache->clear(
'queues-ready' );
172 $cache = ObjectCache::getLocalClusterInstance();
174 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_ANY ),
180 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_DEFAULT ),
199 if ( $this->invalidDomain ) {
201 throw new LogicException(
"Domain '{$this->domain}' is not recognized." );
204 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' ) {
205 $this->
push( $jobs );
209 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
239 public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0,
array $blacklist = [] ) {
244 if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
246 "Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
247 } elseif ( is_string( $qtype ) && !isset(
$wgJobClasses[$qtype] ) ) {
249 throw new JobQueueError(
"Unrecognized job type '$qtype'." );
252 if ( is_string( $qtype ) ) {
253 if ( !in_array( $qtype, $blacklist ) ) {
254 $job = $this->
get( $qtype )->
pop();
257 if ( $flags & self::USE_CACHE ) {
258 if ( !$this->
cache->hasField(
'queues-ready',
'list', self::PROC_CACHE_TTL ) ) {
261 $types = $this->
cache->getField(
'queues-ready',
'list' );
266 if ( $qtype == self::TYPE_DEFAULT ) {
270 $types = array_diff( $types, $blacklist );
278 $this->
cache->clear(
'queues-ready' );
351 $cache = ObjectCache::getLocalClusterInstance();
352 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
357 if (
$type == self::TYPE_DEFAULT ) {
360 $value = count( $queues ) ?
'true' :
'false';
364 return (
$value ===
'true' );
378 if ( is_array( $nonEmpty ) ) {
379 $types = array_merge( $types, $nonEmpty );
381 foreach ( $info[
'types']
as $type ) {
382 if ( !$this->
get( $type )->isEmpty() ) {
403 if ( is_array( $sizes ) ) {
404 $sizeMap = $sizeMap + $sizes;
406 foreach ( $info[
'types']
as $type ) {
407 $sizeMap[
$type] = $this->
get(
$type )->getSize();
421 if ( $this->coalescedQueues ===
null ) {
422 $this->coalescedQueues = [];
425 [
'domain' => $this->domain,
'type' =>
'null' ] + $conf );
426 $loc =
$queue->getCoalesceLocationInternal();
427 if ( !isset( $this->coalescedQueues[$loc] ) ) {
428 $this->coalescedQueues[$loc][
'queue'] =
$queue;
429 $this->coalescedQueues[$loc][
'types'] = [];
431 if (
$type ===
'default' ) {
432 $this->coalescedQueues[$loc][
'types'] = array_merge(
433 $this->coalescedQueues[$loc][
'types'],
437 $this->coalescedQueues[$loc][
'types'][] =
$type;
442 return $this->coalescedQueues;
451 if ( WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
454 $wiki = WikiMap::getWikiIdFromDbDomain( $this->domain );
455 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
457 $cache->makeGlobalKey(
'jobqueue',
'configvalue', $this->domain,
$name ),
458 $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ),
464 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
476 foreach ( $jobs
as $job ) {
478 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgJobTypeConf
Map of job types to configuration arrays.
$wgJobTypesExcludedFromDefaultQueue
Jobs that must be explicitly requested, i.e.
$wgConf
wgConf hold the site configuration.
$wgJobClasses
Maps jobs to their handlers; extensions can add to this to provide custom jobs.
string[] $wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup.
Class to handle enqueueing of background jobs.
getCachedConfigVar( $name)
push( $jobs)
Insert jobs into the respective queues of which they belong.
string $domain
Wiki 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)
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)
bool $invalidDomain
Whether the wiki is not recognized in configuration.
__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.
Handles a simple LRU key/value map with a maximum number of entries.
Class for process caching individual properties of expiring items.
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
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
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
Job queue task description interface.
you have access to all of the normal MediaWiki so you can get a DB use the cache
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))
if(count( $args)< 1) $job