MediaWiki master
JobQueueGroupFactory.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\JobQueue;
8
9use LogicException;
17
28 public const CONSTRUCTOR_OPTIONS = [
33 ];
34
36 private $instances;
37
39 private $options;
40
42 private $readOnlyMode;
43
45 private $statsFactory;
46
48 private $wanCache;
49
51 private $globalIdGenerator;
52
60 public function __construct(
61 ServiceOptions $options,
62 ReadOnlyMode $readOnlyMode,
63 StatsFactory $statsFactory,
64 WANObjectCache $wanCache,
65 GlobalIdGenerator $globalIdGenerator
66 ) {
67 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
68 $this->instances = [];
69 $this->options = $options;
70 $this->readOnlyMode = $readOnlyMode;
71 $this->statsFactory = $statsFactory;
72 $this->wanCache = $wanCache;
73 $this->globalIdGenerator = $globalIdGenerator;
74 }
75
82 public function makeJobQueueGroup( $domain = false ): JobQueueGroup {
83 if ( $domain === false ) {
84 $domain = WikiMap::getCurrentWikiDbDomain()->getId();
85 }
86
87 // Make sure jobs are not getting pushed to bogus wikis. This can confuse
88 // the job runner system into spawning endless RPC requests that fail (T171371).
89 $isCurrentWiki = WikiMap::isCurrentWikiDbDomain( $domain );
90 if ( !$isCurrentWiki ) {
91 $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
92 if ( !in_array( $wikiId, $this->options->get( MainConfigNames::LocalDatabases ) ) ) {
93 // Do not enqueue job that cannot be run (T171371)
94 throw new LogicException( "Domain '{$domain}' is not recognized." );
95 }
96 }
97
98 if ( !isset( $this->instances[$domain] ) ) {
99 $localJobClasses = $isCurrentWiki
100 ? $this->options->get( MainConfigNames::JobClasses )
101 : null;
102
103 $this->instances[$domain] = new JobQueueGroup(
104 $domain,
105 $this->readOnlyMode,
106 $localJobClasses,
107 $this->options->get( MainConfigNames::JobTypeConf ),
109 $this->statsFactory,
110 $this->wanCache,
111 $this->globalIdGenerator
112 );
113 }
114
115 return $this->instances[$domain];
116 }
117}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
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:19
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.