77 if ( !isset( self::$instances[
$domain] ) ) {
86 self::$instances[
$domain]->invalidDomain =
true;
90 return self::$instances[
$domain];
99 self::$instances = [];
117 if ( !isset( $conf[
'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." );
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' );
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 = [] ) {
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' );
324 return array_diff( $this->
getQueueTypes(), $wgJobTypesExcludedFromDefaultQueue );
336 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
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;
440 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
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 ) ];
461 foreach ( $jobs as
$job ) {
463 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );