MediaWiki 1.42.0
JobQueueGroupFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\JobQueue;
22
25use LogicException;
32
43 public const CONSTRUCTOR_OPTIONS = [
48 ];
49
51 private $instances;
52
54 private $options;
55
57 private $readOnlyMode;
58
60 private $statsdDataFactory;
61
63 private $wanCache;
64
66 private $globalIdGenerator;
67
75 public function __construct(
76 ServiceOptions $options,
77 ReadOnlyMode $readOnlyMode,
78 IBufferingStatsdDataFactory $statsdDataFactory,
79 WANObjectCache $wanCache,
80 GlobalIdGenerator $globalIdGenerator
81 ) {
82 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
83 $this->instances = [];
84 $this->options = $options;
85 $this->readOnlyMode = $readOnlyMode;
86 $this->statsdDataFactory = $statsdDataFactory;
87 $this->wanCache = $wanCache;
88 $this->globalIdGenerator = $globalIdGenerator;
89 }
90
97 public function makeJobQueueGroup( $domain = false ): JobQueueGroup {
98 if ( $domain === false ) {
99 $domain = WikiMap::getCurrentWikiDbDomain()->getId();
100 }
101
102 // Make sure jobs are not getting pushed to bogus wikis. This can confuse
103 // the job runner system into spawning endless RPC requests that fail (T171371).
104 $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
105 if (
106 !WikiMap::isCurrentWikiDbDomain( $domain ) &&
107 !in_array( $wikiId, $this->options->get( MainConfigNames::LocalDatabases ) )
108 ) {
109 // Do not enqueue job that cannot be run (T171371)
110 throw new LogicException( "Domain '{$domain}' is not recognized." );
111 }
112
113 $localJobClasses = WikiMap::isCurrentWikiDbDomain( $domain )
114 ? $this->options->get( MainConfigNames::JobClasses )
115 : null;
116
117 if ( !isset( $this->instances[$domain] ) ) {
118 $this->instances[$domain] = new JobQueueGroup(
119 $domain,
120 $this->readOnlyMode,
121 $localJobClasses,
122 $this->options->get( MainConfigNames::JobTypeConf ),
124 $this->statsdDataFactory,
125 $this->wanCache,
126 $this->globalIdGenerator
127 );
128 }
129
130 return $this->instances[$domain];
131 }
132}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Handle enqueueing of background jobs.
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Factory for JobQueueGroup objects.
__construct(ServiceOptions $options, ReadOnlyMode $readOnlyMode, IBufferingStatsdDataFactory $statsdDataFactory, WANObjectCache $wanCache, GlobalIdGenerator $globalIdGenerator)
A class containing constants representing the names of configuration variables.
const JobTypeConf
Name constant for the JobTypeConf setting, for use with Config::get()
const LocalDatabases
Name constant for the LocalDatabases setting, for use with Config::get()
const JobClasses
Name constant for the JobClasses setting, for use with Config::get()
const JobTypesExcludedFromDefaultQueue
Name constant for the JobTypesExcludedFromDefaultQueue setting, for use with Config::get()
Tools for dealing with other locally-hosted wikis.
Definition WikiMap.php:31
Multi-datacenter aware caching interface.
Determine whether a site is currently in read-only mode.
Class for getting statistically unique IDs without a central coordinator.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.