77 if ( !isset( self::$instances[
$domain] ) ) {
78 $reason = MediaWikiServices::getInstance()
79 ->getConfiguredReadOnlyMode()
89 self::$instances[
$domain]->invalidDomain =
true;
93 return self::$instances[
$domain];
102 self::$instances = [];
120 if ( !isset( $conf[
'readOnlyReason'] ) ) {
133 $services = MediaWikiServices::getInstance();
134 $conf[
'stats'] = $services->getStatsdDataFactory();
135 $conf[
'wanCache'] = $services->getMainWANObjectCache();
136 $conf[
'idGenerator'] = $services->getGlobalIdGenerator();
151 public function push( $jobs ) {
154 if ( $this->invalidDomain ) {
156 $e =
new LogicException(
"Domain '{$this->domain}' is not recognized." );
161 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
162 if ( $jobs === [] ) {
169 foreach ( $jobs as
$job ) {
170 $jobsByType[
$job->getType()][] =
$job;
173 foreach ( $jobsByType as
$type => $jobs ) {
177 if ( $this->cache->hasField(
'queues-ready',
'list' ) ) {
178 $list = $this->cache->getField(
'queues-ready',
'list' );
179 if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
180 $this->cache->clear(
'queues-ready' );
186 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_ANY ),
192 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_DEFAULT ),
207 if ( $this->invalidDomain ) {
209 throw new LogicException(
"Domain '{$this->domain}' is not recognized." );
212 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' ) {
213 $this->
push( $jobs );
217 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
236 public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = [] ) {
243 "Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
244 } elseif ( is_string( $qtype ) && !isset(
$wgJobClasses[$qtype] ) ) {
246 throw new JobQueueError(
"Unrecognized job type '$qtype'." );
249 if ( is_string( $qtype ) ) {
250 if ( !in_array( $qtype, $blacklist ) ) {
251 $job = $this->
get( $qtype )->
pop();
254 if ( $flags & self::USE_CACHE ) {
255 if ( !$this->cache->hasField(
'queues-ready',
'list', self::PROC_CACHE_TTL ) ) {
258 $types = $this->cache->getField(
'queues-ready',
'list' );
263 if ( $qtype == self::TYPE_DEFAULT ) {
267 $types = array_diff( $types, $blacklist );
270 foreach ( $types as
$type ) {
275 $this->cache->clear(
'queues-ready' );
337 return array_diff( $this->
getQueueTypes(), $wgJobTypesExcludedFromDefaultQueue );
349 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
352 if ( $value ===
false ) {
354 if (
$type == self::TYPE_DEFAULT ) {
357 $value = count( $queues ) ?
'true' :
'false';
358 $cache->add( $key, $value, 15 );
361 return ( $value ===
'true' );
375 if ( is_array( $nonEmpty ) ) {
376 $types = array_merge( $types, $nonEmpty );
378 foreach ( $info[
'types'] as
$type ) {
379 if ( !$this->
get( $type )->isEmpty() ) {
400 if ( is_array( $sizes ) ) {
403 foreach ( $info[
'types'] as
$type ) {
404 $sizeMap[
$type] = $this->
get(
$type )->getSize();
419 if ( $this->coalescedQueues ===
null ) {
420 $this->coalescedQueues = [];
423 [
'domain' => $this->domain,
'type' =>
'null' ] + $conf );
424 $loc =
$queue->getCoalesceLocationInternal();
425 if ( !isset( $this->coalescedQueues[$loc] ) ) {
426 $this->coalescedQueues[$loc][
'queue'] =
$queue;
427 $this->coalescedQueues[$loc][
'types'] = [];
429 if (
$type ===
'default' ) {
430 $this->coalescedQueues[$loc][
'types'] = array_merge(
431 $this->coalescedQueues[$loc][
'types'],
435 $this->coalescedQueues[$loc][
'types'][] =
$type;
450 return $GLOBALS[$name];
453 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
455 $cache->makeGlobalKey(
'jobqueue',
'configvalue', $this->domain, $name ),
456 $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ),
457 function () use ( $wiki, $name ) {
460 return [
'v' =>
$wgConf->getConfig( $wiki, $name ) ];
462 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
474 foreach ( $jobs as
$job ) {
476 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );