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();
138 public function push( $jobs ) {
141 if ( $this->invalidDomain ) {
143 $e =
new LogicException(
"Domain '{$this->domain}' is not recognized." );
144 MWExceptionHandler::logException( $e );
148 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
149 if ( $jobs === [] ) {
156 foreach ( $jobs as
$job ) {
157 $jobsByType[
$job->getType()][] =
$job;
160 foreach ( $jobsByType as
$type => $jobs ) {
164 if ( $this->cache->hasField(
'queues-ready',
'list' ) ) {
165 $list = $this->cache->getField(
'queues-ready',
'list' );
166 if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
167 $this->cache->clear(
'queues-ready' );
171 $cache = ObjectCache::getLocalClusterInstance();
173 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_ANY ),
179 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_DEFAULT ),
194 if ( $this->invalidDomain ) {
196 throw new LogicException(
"Domain '{$this->domain}' is not recognized." );
199 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' ) {
200 $this->
push( $jobs );
204 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
223 public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = [] ) {
228 if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
230 "Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
231 } elseif ( is_string( $qtype ) && !isset(
$wgJobClasses[$qtype] ) ) {
233 throw new JobQueueError(
"Unrecognized job type '$qtype'." );
236 if ( is_string( $qtype ) ) {
237 if ( !in_array( $qtype, $blacklist ) ) {
238 $job = $this->
get( $qtype )->
pop();
241 if ( $flags & self::USE_CACHE ) {
242 if ( !$this->cache->hasField(
'queues-ready',
'list', self::PROC_CACHE_TTL ) ) {
245 $types = $this->cache->getField(
'queues-ready',
'list' );
250 if ( $qtype == self::TYPE_DEFAULT ) {
254 $types = array_diff( $types, $blacklist );
257 foreach ( $types as
$type ) {
262 $this->cache->clear(
'queues-ready' );
335 $cache = ObjectCache::getLocalClusterInstance();
336 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
338 $value =
$cache->get( $key );
339 if ( $value ===
false ) {
341 if (
$type == self::TYPE_DEFAULT ) {
344 $value = count( $queues ) ?
'true' :
'false';
345 $cache->add( $key, $value, 15 );
348 return ( $value ===
'true' );
362 if ( is_array( $nonEmpty ) ) {
363 $types = array_merge( $types, $nonEmpty );
365 foreach ( $info[
'types'] as
$type ) {
366 if ( !$this->
get( $type )->isEmpty() ) {
387 if ( is_array( $sizes ) ) {
388 $sizeMap = $sizeMap + $sizes;
390 foreach ( $info[
'types'] as
$type ) {
391 $sizeMap[
$type] = $this->
get(
$type )->getSize();
406 if ( $this->coalescedQueues ===
null ) {
407 $this->coalescedQueues = [];
410 [
'domain' => $this->domain,
'type' =>
'null' ] + $conf );
411 $loc =
$queue->getCoalesceLocationInternal();
412 if ( !isset( $this->coalescedQueues[$loc] ) ) {
413 $this->coalescedQueues[$loc][
'queue'] =
$queue;
414 $this->coalescedQueues[$loc][
'types'] = [];
416 if (
$type ===
'default' ) {
417 $this->coalescedQueues[$loc][
'types'] = array_merge(
418 $this->coalescedQueues[$loc][
'types'],
422 $this->coalescedQueues[$loc][
'types'][] =
$type;
427 return $this->coalescedQueues;
436 if ( WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
439 $wiki = WikiMap::getWikiIdFromDbDomain( $this->domain );
440 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
441 $value =
$cache->getWithSetCallback(
442 $cache->makeGlobalKey(
'jobqueue',
'configvalue', $this->domain, $name ),
443 $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ),
444 function () use ( $wiki, $name ) {
447 return [
'v' =>
$wgConf->getConfig( $wiki, $name ) ];
449 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
461 foreach ( $jobs as
$job ) {
463 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );
$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.
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.
waitForBackups()
Wait for any replica DBs or backup queue servers to catch up.
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.
ack(RunnableJob $job)
Acknowledge that a job was completed.
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.
deduplicateRootJob(RunnableJob $job)
Register the "root job" of a given job into the queue for de-duplication.
static factory(array $params)
Get a job queue object of the specified type.
Handles a simple LRU key/value map with a maximum number of entries.
Interface for serializable objects that describe a job queue task.
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
if(count( $args)< 1) $job