2021-03-17 12:37:06 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\JobQueue;
|
|
|
|
|
|
|
|
|
|
use IBufferingStatsdDataFactory;
|
|
|
|
|
use JobQueueGroup;
|
2023-07-11 09:02:03 +00:00
|
|
|
use LogicException;
|
2021-03-17 12:37:06 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2022-04-25 15:19:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-02-23 20:44:38 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2021-03-17 12:37:06 +00:00
|
|
|
use WANObjectCache;
|
2023-05-04 21:41:21 +00:00
|
|
|
use Wikimedia\Rdbms\ConfiguredReadOnlyMode;
|
2021-03-17 12:37:06 +00:00
|
|
|
use Wikimedia\UUID\GlobalIdGenerator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to construct JobQueueGroups
|
|
|
|
|
*
|
|
|
|
|
* @ingroup JobQueue
|
|
|
|
|
* @since 1.37
|
|
|
|
|
*/
|
|
|
|
|
class JobQueueGroupFactory {
|
|
|
|
|
/**
|
|
|
|
|
* @internal For use by ServiceWiring
|
|
|
|
|
*/
|
|
|
|
|
public const CONSTRUCTOR_OPTIONS = [
|
2022-04-25 15:19:41 +00:00
|
|
|
MainConfigNames::JobClasses,
|
|
|
|
|
MainConfigNames::JobTypeConf,
|
|
|
|
|
MainConfigNames::JobTypesExcludedFromDefaultQueue,
|
|
|
|
|
MainConfigNames::LocalDatabases,
|
2021-03-17 12:37:06 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** @var JobQueueGroup[] */
|
|
|
|
|
private $instances;
|
|
|
|
|
|
|
|
|
|
/** @var ServiceOptions */
|
|
|
|
|
private $options;
|
|
|
|
|
|
|
|
|
|
/** @var ConfiguredReadOnlyMode */
|
|
|
|
|
private $readOnlyMode;
|
|
|
|
|
|
|
|
|
|
/** @var IBufferingStatsdDataFactory */
|
|
|
|
|
private $statsdDataFactory;
|
|
|
|
|
|
|
|
|
|
/** @var WANObjectCache */
|
|
|
|
|
private $wanCache;
|
|
|
|
|
|
|
|
|
|
/** @var GlobalIdGenerator */
|
|
|
|
|
private $globalIdGenerator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ServiceOptions $options
|
|
|
|
|
* @param ConfiguredReadOnlyMode $readOnlyMode
|
|
|
|
|
* @param IBufferingStatsdDataFactory $statsdDataFactory
|
|
|
|
|
* @param WANObjectCache $wanCache
|
|
|
|
|
* @param GlobalIdGenerator $globalIdGenerator
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ServiceOptions $options,
|
|
|
|
|
ConfiguredReadOnlyMode $readOnlyMode,
|
|
|
|
|
IBufferingStatsdDataFactory $statsdDataFactory,
|
|
|
|
|
WANObjectCache $wanCache,
|
|
|
|
|
GlobalIdGenerator $globalIdGenerator
|
|
|
|
|
) {
|
|
|
|
|
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
|
|
|
|
$this->instances = [];
|
|
|
|
|
$this->options = $options;
|
|
|
|
|
$this->readOnlyMode = $readOnlyMode;
|
|
|
|
|
$this->statsdDataFactory = $statsdDataFactory;
|
|
|
|
|
$this->wanCache = $wanCache;
|
|
|
|
|
$this->globalIdGenerator = $globalIdGenerator;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 09:02:03 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $domain
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
private function getCachedJobClasses( $domain ) {
|
|
|
|
|
$name = MainConfigNames::JobClasses;
|
|
|
|
|
if ( WikiMap::isCurrentWikiDbDomain( $domain ) ) {
|
|
|
|
|
return $this->options->get( $name ); // common case
|
|
|
|
|
} else {
|
|
|
|
|
$configName = 'wg' . $name;
|
|
|
|
|
$wiki = WikiMap::getWikiIdFromDbDomain( $domain );
|
|
|
|
|
$value = $this->wanCache->getWithSetCallback(
|
|
|
|
|
$this->wanCache->makeGlobalKey(
|
|
|
|
|
'jobqueue',
|
|
|
|
|
'configvalue',
|
|
|
|
|
$domain,
|
|
|
|
|
$configName
|
|
|
|
|
),
|
|
|
|
|
$this->wanCache::TTL_DAY + mt_rand( 0, $this->wanCache::TTL_DAY ),
|
|
|
|
|
static function () use ( $wiki, $configName ) {
|
|
|
|
|
global $wgConf;
|
|
|
|
|
// @TODO: use the full domain ID here
|
|
|
|
|
// NOTE: The 'wg' config is needed here by ::getConfig(). SiteConfiguration
|
|
|
|
|
// will have to be refactored to use our config system.
|
|
|
|
|
return [ 'v' => $wgConf->getConfig( $wiki, $configName ) ];
|
|
|
|
|
},
|
|
|
|
|
[ 'pcTTL' => $this->wanCache::TTL_PROC_LONG ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $value['v'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 12:37:06 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.37
|
|
|
|
|
*
|
|
|
|
|
* @param false|string $domain Wiki domain ID. False uses the current wiki domain ID
|
|
|
|
|
* @return JobQueueGroup
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function makeJobQueueGroup( $domain = false ): JobQueueGroup {
|
2021-03-17 12:37:06 +00:00
|
|
|
if ( $domain === false ) {
|
|
|
|
|
$domain = WikiMap::getCurrentWikiDbDomain()->getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $this->instances[$domain] ) ) {
|
|
|
|
|
// Make sure jobs are not getting pushed to bogus wikis. This can confuse
|
|
|
|
|
// the job runner system into spawning endless RPC requests that fail (T171371).
|
|
|
|
|
$wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
|
|
|
|
|
if (
|
|
|
|
|
!WikiMap::isCurrentWikiDbDomain( $domain ) &&
|
2022-04-25 15:19:41 +00:00
|
|
|
!in_array( $wikiId, $this->options->get( MainConfigNames::LocalDatabases ) )
|
2021-03-17 12:37:06 +00:00
|
|
|
) {
|
2023-07-11 09:02:03 +00:00
|
|
|
// Do not enqueue job that cannot be run (T171371)
|
|
|
|
|
throw new LogicException( "Domain '{$domain}' is not recognized." );
|
2021-03-17 12:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->instances[$domain] = new JobQueueGroup(
|
|
|
|
|
$domain,
|
|
|
|
|
$this->readOnlyMode,
|
2023-07-11 09:02:03 +00:00
|
|
|
$this->getCachedJobClasses( $domain ),
|
2022-04-25 15:19:41 +00:00
|
|
|
$this->options->get( MainConfigNames::JobTypeConf ),
|
|
|
|
|
$this->options->get( MainConfigNames::JobTypesExcludedFromDefaultQueue ),
|
2021-03-17 12:37:06 +00:00
|
|
|
$this->statsdDataFactory,
|
|
|
|
|
$this->wanCache,
|
|
|
|
|
$this->globalIdGenerator
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->instances[$domain];
|
|
|
|
|
}
|
|
|
|
|
}
|