69 public static function singleton( $domain =
false ) {
76 if ( !isset( self::$instances[
$domain] ) ) {
85 self::$instances[$domain]->invalidWiki =
true;
89 return self::$instances[$domain];
98 self::$instances = [];
110 $conf = [
'wiki' => $this->domain,
'type' =>
$type ];
117 if ( !isset( $conf[
'readOnlyReason'] ) ) {
118 $conf[
'readOnlyReason'] = $this->readOnlyReason;
134 public function push( $jobs ) {
137 if ( $this->invalidWiki ) {
139 $e =
new LogicException(
"Domain '{$this->domain}' is not recognized." );
140 MWExceptionHandler::logException(
$e );
144 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
145 if ( !count( $jobs ) ) {
152 foreach ( $jobs as
$job ) {
153 $jobsByType[
$job->getType()][] =
$job;
156 foreach ( $jobsByType as
$type => $jobs ) {
160 if ( $this->
cache->hasField(
'queues-ready',
'list' ) ) {
161 $list = $this->
cache->getField(
'queues-ready',
'list' );
162 if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
163 $this->
cache->clear(
'queues-ready' );
167 $cache = ObjectCache::getLocalClusterInstance();
169 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_ANY ),
175 $cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs', self::TYPE_DEFAULT ),
194 if ( $this->invalidWiki ) {
196 throw new LogicException(
"Domain '{$this->domain}' is not recognized." );
199 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' ) {
200 $this->
push( $jobs );
204 $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
234 public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0,
array $blacklist = [] ) {
237 if ( is_string( $qtype ) ) {
238 if ( !in_array( $qtype, $blacklist ) ) {
239 $job = $this->
get( $qtype )->
pop();
242 if ( $flags & self::USE_CACHE ) {
243 if ( !$this->
cache->hasField(
'queues-ready',
'list', self::PROC_CACHE_TTL ) ) {
246 $types = $this->
cache->getField(
'queues-ready',
'list' );
251 if ( $qtype == self::TYPE_DEFAULT ) {
255 $types = array_diff( $types, $blacklist );
258 foreach ( $types as
$type ) {
263 $this->
cache->clear(
'queues-ready' );
336 $cache = ObjectCache::getLocalClusterInstance();
337 $key =
$cache->makeGlobalKey(
'jobqueue', $this->domain,
'hasjobs',
$type );
342 if (
$type == self::TYPE_DEFAULT ) {
345 $value = count( $queues ) ?
'true' :
'false';
349 return (
$value ===
'true' );
360 $nonEmpty = $info[
'queue']->getSiblingQueuesWithJobs( $this->
getQueueTypes() );
361 if ( is_array( $nonEmpty ) ) {
362 $types = array_merge( $types, $nonEmpty );
364 foreach ( $info[
'types'] as
$type ) {
365 if ( !$this->
get( $type )->isEmpty() ) {
383 $sizes = $info[
'queue']->getSiblingQueueSizes( $this->
getQueueTypes() );
384 if ( is_array( $sizes ) ) {
385 $sizeMap = $sizeMap + $sizes;
387 foreach ( $info[
'types'] as
$type ) {
388 $sizeMap[
$type] = $this->
get(
$type )->getSize();
402 if ( $this->coalescedQueues ===
null ) {
403 $this->coalescedQueues = [];
406 [
'wiki' => $this->domain,
'type' =>
'null' ] + $conf );
407 $loc =
$queue->getCoalesceLocationInternal();
408 if ( !isset( $this->coalescedQueues[$loc] ) ) {
409 $this->coalescedQueues[$loc][
'queue'] =
$queue;
410 $this->coalescedQueues[$loc][
'types'] = [];
412 if (
$type ===
'default' ) {
413 $this->coalescedQueues[$loc][
'types'] = array_merge(
414 $this->coalescedQueues[$loc][
'types'],
418 $this->coalescedQueues[$loc][
'types'][] =
$type;
423 return $this->coalescedQueues;
436 $cache = ObjectCache::getMainWANInstance();
438 $cache->makeGlobalKey(
'jobqueue',
'configvalue', $this->domain, $name ),
439 $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ),
440 function () use ( $wiki, $name ) {
443 return [
'v' =>
$wgConf->getConfig( $wiki, $name ) ];
445 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
457 foreach ( $jobs as
$job ) {
459 throw new InvalidArgumentException(
"Expected IJobSpecification objects" );
$wgJobTypeConf
Map of job types to configuration arrays.
$wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
$wgJobTypesExcludedFromDefaultQueue
Jobs that must be explicitly requested, i.e.
$wgConf
wgConf hold the site configuration.
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Enqueue lazy-pushed jobs that have accumulated from JobQueueGroup.
Class to handle enqueueing of background jobs.
getCachedConfigVar( $name)
push( $jobs)
Insert jobs into the respective queues of which they belong.
string $domain
Wiki DB domain ID.
getQueueSizes()
Get the size of the queus for a list of job types.
ack(Job $job)
Acknowledge that a job was completed.
static pushLazyJobs()
Push all jobs buffered via lazyPush() into their respective queues.
waitForBackups()
Wait for any replica DBs or backup queue servers to catch up.
deduplicateRootJob(Job $job)
Register the "root job" of a given job into the queue for de-duplication.
array $coalescedQueues
Map of (bucket => (queue => JobQueue, types => list of types)
static singleton( $domain=false)
bool $invalidWiki
Whether the wiki is not recognized in configuration.
string bool $readOnlyReason
Read only rationale (or false if r/w)
getDefaultQueueTypes()
Get the list of default queue types.
lazyPush( $jobs)
Buffer jobs for insertion via push() or call it now if in CLI mode.
pop( $qtype=self::TYPE_DEFAULT, $flags=0, array $blacklist=[])
Pop a job off one of the job queues.
static destroySingletons()
Destroy the singleton instances.
queuesHaveJobs( $type=self::TYPE_ANY)
Check if there are any queues with jobs (this is cached)
__construct( $domain, $readOnlyReason)
static JobQueueGroup[] $instances
getQueuesWithJobs()
Get the list of job types that have non-empty queues.
assertValidJobs(array $jobs)
getQueueTypes()
Get the list of queue types.
static factory(array $params)
Get a job queue object of the specified type.
Class to both describe a background job and handle jobs.
Handles a simple LRU key/value map with a maximum number of entries.
Class for process caching individual properties of expiring items.
static getCurrentWikiDbDomain()
static getWikiIdFromDomain( $domain)
Get the wiki ID of a database domain.
static isCurrentWikiDbDomain( $domain)
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
Job queue task description interface.
you have access to all of the normal MediaWiki so you can get a DB use the cache
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(count( $args)< 1) $job