MediaWiki  master
JobQueueGroupFactory.php
Go to the documentation of this file.
1 <?php
22 
25 use JobQueueGroup;
27 use WANObjectCache;
28 use WikiMap;
30 
41  public const CONSTRUCTOR_OPTIONS = [
42  'JobClasses',
43  'JobTypeConf',
44  'JobTypesExcludedFromDefaultQueue',
45  'LocalDatabases',
46  ];
47 
49  private $instances;
50 
52  private $options;
53 
55  private $readOnlyMode;
56 
59 
61  private $wanCache;
62 
65 
73  public function __construct(
79  ) {
80  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
81  $this->instances = [];
82  $this->options = $options;
83  $this->readOnlyMode = $readOnlyMode;
84  $this->statsdDataFactory = $statsdDataFactory;
85  $this->wanCache = $wanCache;
86  $this->globalIdGenerator = $globalIdGenerator;
87  }
88 
95  public function makeJobQueueGroup( $domain = false ): JobQueueGroup {
96  if ( $domain === false ) {
97  $domain = WikiMap::getCurrentWikiDbDomain()->getId();
98  }
99 
100  if ( !isset( $this->instances[$domain] ) ) {
101  // Make sure jobs are not getting pushed to bogus wikis. This can confuse
102  // the job runner system into spawning endless RPC requests that fail (T171371).
103  $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
104  if (
105  !WikiMap::isCurrentWikiDbDomain( $domain ) &&
106  !in_array( $wikiId, $this->options->get( 'LocalDatabases' ) )
107  ) {
108  $invalidDomain = true;
109  } else {
110  $invalidDomain = false;
111  }
112 
113  $this->instances[$domain] = new JobQueueGroup(
114  $domain,
115  $this->readOnlyMode,
116  $invalidDomain,
117  $this->options->get( 'JobClasses' ),
118  $this->options->get( 'JobTypeConf' ),
119  $this->options->get( 'JobTypesExcludedFromDefaultQueue' ),
120  $this->statsdDataFactory,
121  $this->wanCache,
122  $this->globalIdGenerator
123  );
124  }
125 
126  return $this->instances[$domain];
127  }
128 }
WikiMap\isCurrentWikiDbDomain
static isCurrentWikiDbDomain( $domain)
Definition: WikiMap.php:312
WikiMap\getCurrentWikiDbDomain
static getCurrentWikiDbDomain()
Definition: WikiMap.php:293
Wikimedia\UUID\GlobalIdGenerator
Class for getting statistically unique IDs without a central coordinator.
Definition: GlobalIdGenerator.php:34
MediaWiki\JobQueue\JobQueueGroupFactory\$instances
JobQueueGroup[] $instances
Definition: JobQueueGroupFactory.php:49
ConfiguredReadOnlyMode
A read-only mode service which does not depend on LoadBalancer.
Definition: ConfiguredReadOnlyMode.php:9
MediaWiki\JobQueue
Definition: JobQueueGroupFactory.php:21
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
WikiMap\getWikiIdFromDbDomain
static getWikiIdFromDbDomain( $domain)
Get the wiki ID of a database domain.
Definition: WikiMap.php:269
MediaWiki\JobQueue\JobQueueGroupFactory\$globalIdGenerator
GlobalIdGenerator $globalIdGenerator
Definition: JobQueueGroupFactory.php:64
MediaWiki\JobQueue\JobQueueGroupFactory\$statsdDataFactory
IBufferingStatsdDataFactory $statsdDataFactory
Definition: JobQueueGroupFactory.php:58
MediaWiki\JobQueue\JobQueueGroupFactory
Class to construct JobQueueGroups.
Definition: JobQueueGroupFactory.php:37
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:137
IBufferingStatsdDataFactory
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
Definition: IBufferingStatsdDataFactory.php:13
MediaWiki\JobQueue\JobQueueGroupFactory\$readOnlyMode
ConfiguredReadOnlyMode $readOnlyMode
Definition: JobQueueGroupFactory.php:55
WikiMap
Helper tools for dealing with other locally-hosted wikis.
Definition: WikiMap.php:29
MediaWiki\JobQueue\JobQueueGroupFactory\makeJobQueueGroup
makeJobQueueGroup( $domain=false)
Definition: JobQueueGroupFactory.php:95
MediaWiki\JobQueue\JobQueueGroupFactory\$options
ServiceOptions $options
Definition: JobQueueGroupFactory.php:52
MediaWiki\JobQueue\JobQueueGroupFactory\$wanCache
WANObjectCache $wanCache
Definition: JobQueueGroupFactory.php:61
MediaWiki\JobQueue\JobQueueGroupFactory\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: JobQueueGroupFactory.php:41
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:71
JobQueueGroup
Class to handle enqueueing of background jobs.
Definition: JobQueueGroup.php:32
MediaWiki\JobQueue\JobQueueGroupFactory\__construct
__construct(ServiceOptions $options, ConfiguredReadOnlyMode $readOnlyMode, IBufferingStatsdDataFactory $statsdDataFactory, WANObjectCache $wanCache, GlobalIdGenerator $globalIdGenerator)
Definition: JobQueueGroupFactory.php:73