MediaWiki master
JobQueueGroupFactory.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\JobQueue;
8
9use LogicException;
10use MediaWiki\Config\ServiceOptions;
11use MediaWiki\MainConfigNames;
12use MediaWiki\WikiMap\WikiMap;
13use Wikimedia\ObjectCache\BagOStuff;
14use Wikimedia\Rdbms\ReadOnlyMode;
15use Wikimedia\Stats\StatsFactory;
16use Wikimedia\UUID\GlobalIdGenerator;
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 $localClusterCache;
49
51 private $globalIdGenerator;
52
60 public function __construct(
61 ServiceOptions $options,
62 ReadOnlyMode $readOnlyMode,
63 StatsFactory $statsFactory,
64 BagOStuff $localClusterCache,
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->localClusterCache = $localClusterCache;
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->localClusterCache,
111 $this->globalIdGenerator
112 );
113 }
114
115 return $this->instances[$domain];
116 }
117}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:72
A class for passing options to services.
Factory for JobQueueGroup objects.
__construct(ServiceOptions $options, ReadOnlyMode $readOnlyMode, StatsFactory $statsFactory, BagOStuff $localClusterCache, GlobalIdGenerator $globalIdGenerator)
Handle enqueueing of background jobs.
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().
Abstract class for any ephemeral data store.
Definition BagOStuff.php:73
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.