MediaWiki 1.44.0
JobQueueGroupFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\JobQueue;
22
23use LogicException;
31
42 public const CONSTRUCTOR_OPTIONS = [
47 ];
48
50 private $instances;
51
53 private $options;
54
56 private $readOnlyMode;
57
59 private $statsFactory;
60
62 private $wanCache;
63
65 private $globalIdGenerator;
66
74 public function __construct(
75 ServiceOptions $options,
76 ReadOnlyMode $readOnlyMode,
77 StatsFactory $statsFactory,
78 WANObjectCache $wanCache,
79 GlobalIdGenerator $globalIdGenerator
80 ) {
81 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
82 $this->instances = [];
83 $this->options = $options;
84 $this->readOnlyMode = $readOnlyMode;
85 $this->statsFactory = $statsFactory;
86 $this->wanCache = $wanCache;
87 $this->globalIdGenerator = $globalIdGenerator;
88 }
89
96 public function makeJobQueueGroup( $domain = false ): JobQueueGroup {
97 if ( $domain === false ) {
98 $domain = WikiMap::getCurrentWikiDbDomain()->getId();
99 }
100
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 $isCurrentWiki = WikiMap::isCurrentWikiDbDomain( $domain );
104 if ( !$isCurrentWiki ) {
105 $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
106 if ( !in_array( $wikiId, $this->options->get( MainConfigNames::LocalDatabases ) ) ) {
107 // Do not enqueue job that cannot be run (T171371)
108 throw new LogicException( "Domain '{$domain}' is not recognized." );
109 }
110 }
111
112 if ( !isset( $this->instances[$domain] ) ) {
113 $localJobClasses = $isCurrentWiki
114 ? $this->options->get( MainConfigNames::JobClasses )
115 : null;
116
117 $this->instances[$domain] = new JobQueueGroup(
118 $domain,
119 $this->readOnlyMode,
120 $localJobClasses,
121 $this->options->get( MainConfigNames::JobTypeConf ),
123 $this->statsFactory,
124 $this->wanCache,
125 $this->globalIdGenerator
126 );
127 }
128
129 return $this->instances[$domain];
130 }
131}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:82
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, StatsFactory $statsFactory, WANObjectCache $wanCache, GlobalIdGenerator $globalIdGenerator)
Handle enqueueing of background jobs.
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.
This is the primary interface for validating metrics definitions, caching defined metrics,...
Class for getting statistically unique IDs without a central coordinator.