| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\JobQueue; |
| 22 |
|
| 23 |
use JobQueueGroup; |
| 24 |
use LogicException; |
| 25 |
use MediaWiki\Config\ServiceOptions; |
| 26 |
use MediaWiki\MainConfigNames; |
| 27 |
use MediaWiki\WikiMap\WikiMap; |
| 28 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 29 |
use Wikimedia\Rdbms\ReadOnlyMode; |
| 30 |
use Wikimedia\Stats\IBufferingStatsdDataFactory; |
| 31 |
use Wikimedia\UUID\GlobalIdGenerator; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class JobQueueGroupFactory { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public const CONSTRUCTOR_OPTIONS = [ |
| 44 |
MainConfigNames::JobClasses, |
| 45 |
MainConfigNames::JobTypeConf, |
| 46 |
MainConfigNames::JobTypesExcludedFromDefaultQueue, |
| 47 |
MainConfigNames::LocalDatabases, |
| 48 |
]; |
| 49 |
|
| 50 |
|
| 51 |
private $instances; |
| 52 |
|
| 53 |
|
| 54 |
private $options; |
| 55 |
|
| 56 |
|
| 57 |
private $readOnlyMode; |
| 58 |
|
| 59 |
|
| 60 |
private $statsdDataFactory; |
| 61 |
|
| 62 |
|
| 63 |
private $wanCache; |
| 64 |
|
| 65 |
|
| 66 |
private $globalIdGenerator; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 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 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function makeJobQueueGroup( $domain = false ): JobQueueGroup { |
| 98 |
if ( $domain === false ) { |
| 99 |
$domain = WikiMap::getCurrentWikiDbDomain()->getId(); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
$wikiId = WikiMap::getWikiIdFromDbDomain( $domain ); |
| 105 |
if ( |
| 106 |
!WikiMap::isCurrentWikiDbDomain( $domain ) && |
| 107 |
!in_array( $wikiId, $this->options->get( MainConfigNames::LocalDatabases ) ) |
| 108 |
) { |
| 109 |
|
| 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 ), |
| 123 |
$this->options->get( MainConfigNames::JobTypesExcludedFromDefaultQueue ), |
| 124 |
$this->statsdDataFactory, |
| 125 |
$this->wanCache, |
| 126 |
$this->globalIdGenerator |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
return $this->instances[$domain]; |
| 131 |
} |
| 132 |
} |