Go to the documentation of this file.
27 use Wikimedia\ScopedCallback;
64 if ( isset(
$params[
'server'] ) ) {
65 $this->
server = $params[
'server'];
66 } elseif ( isset(
$params[
'cluster'] ) && is_string(
$params[
'cluster'] ) ) {
67 $this->cluster =
$params[
'cluster'];
74 return [
'random',
'timestamp',
'fifo' ];
90 $found =
$dbr->selectField(
91 'job',
'1', [
'job_cmd' => $this->
type,
'job_token' =>
'' ], __METHOD__
107 $size = $this->
cache->get( $key );
108 if ( is_int( $size ) ) {
116 $size = (int)
$dbr->selectField(
'job',
'COUNT(*)',
117 [
'job_cmd' => $this->type,
'job_token' =>
'' ],
123 $this->
cache->set( $key, $size, self::CACHE_TTL_SHORT );
133 if ( $this->claimTTL <= 0 ) {
139 $count = $this->
cache->get( $key );
140 if ( is_int( $count ) ) {
148 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
149 [
'job_cmd' => $this->type,
"job_token != {$dbr->addQuotes( '' )}" ],
155 $this->
cache->set( $key, $count, self::CACHE_TTL_SHORT );
166 if ( $this->claimTTL <= 0 ) {
172 $count = $this->
cache->get( $key );
173 if ( is_int( $count ) ) {
181 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
183 'job_cmd' => $this->type,
184 "job_token != {$dbr->addQuotes( '' )}",
185 "job_attempts >= " .
$dbr->addQuotes( $this->maxTries )
193 $this->
cache->set( $key, $count, self::CACHE_TTL_SHORT );
219 $dbw->onTransactionPreCommitOrIdle(
239 if ( $jobs === [] ) {
245 foreach ( $jobs
as $job ) {
247 if (
$job->ignoreDuplicates() ) {
248 $rowSet[$row[
'job_sha1']] = $row;
254 if ( $flags & self::QOS_ATOMIC ) {
259 if (
count( $rowSet ) ) {
263 'job_sha1' => array_keys( $rowSet ),
268 foreach (
$res as $row ) {
269 wfDebug(
"Job with hash '{$row->job_sha1}' is a duplicate.\n" );
270 unset( $rowSet[$row->job_sha1] );
274 $rows = array_merge( $rowList, array_values( $rowSet ) );
276 foreach ( array_chunk(
$rows, 50 )
as $rowBatch ) {
277 $dbw->
insert(
'job', $rowBatch, $method );
286 if ( $flags & self::QOS_ATOMIC ) {
305 if ( in_array( $this->order, [
'fifo',
'timestamp' ] ) ) {
308 $rand = mt_rand( 0, self::MAX_JOB_RANDOM );
309 $gte = (bool)mt_rand( 0, 1 );
320 self::extractBlob( $row->job_params ) );
321 $job->setMetadata(
'id', $row->job_id );
322 $job->setMetadata(
'timestamp', $row->job_timestamp );
326 if ( !
$job || mt_rand( 0, 9 ) == 0 ) {
354 $invertedDirection =
false;
363 $ineq = $gte ?
'>=' :
'<=';
364 $dir = $gte ?
'ASC' :
'DESC';
365 $row = $dbw->selectRow(
'job', self::selectFields(),
367 'job_cmd' => $this->
type,
369 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ],
371 [
'ORDER BY' =>
"job_random {$dir}" ]
373 if ( !$row && !$invertedDirection ) {
375 $invertedDirection =
true;
382 $row = $dbw->selectRow(
'job', self::selectFields(),
384 'job_cmd' => $this->
type,
388 [
'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) ]
400 'job_token' => $uuid,
401 'job_token_timestamp' => $dbw->timestamp(),
402 'job_attempts = job_attempts+1' ],
403 [
'job_cmd' =>
$this->type,
'job_id' => $row->job_id,
'job_token' =>
'' ],
408 if ( !$dbw->affectedRows() ) {
432 if ( $dbw->getType() ===
'mysql' ) {
437 $dbw->query(
"UPDATE {$dbw->tableName( 'job' )} " .
439 "job_token = {$dbw->addQuotes( $uuid ) }, " .
440 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
441 "job_attempts = job_attempts+1 " .
443 "job_cmd = {$dbw->addQuotes( $this->type )} " .
444 "AND job_token = {$dbw->addQuotes( '' )} " .
445 ") ORDER BY job_id ASC LIMIT 1",
453 'job_token' => $uuid,
454 'job_token_timestamp' => $dbw->timestamp(),
455 'job_attempts = job_attempts+1' ],
457 $dbw->selectSQLText(
'job',
'job_id',
458 [
'job_cmd' => $this->
type,
'job_token' =>
'' ],
460 [
'ORDER BY' =>
'job_id ASC',
'LIMIT' => 1 ] ) .
467 if ( $dbw->affectedRows() ) {
468 $row = $dbw->selectRow(
'job', self::selectFields(),
469 [
'job_cmd' => $this->
type,
'job_token' => $uuid ], __METHOD__
472 wfDebug(
"Row deleted as duplicate by another process.\n" );
488 $id =
$job->getMetadata(
'id' );
489 if ( $id ===
null ) {
490 throw new MWException(
"Job of type '{$job->getType()}' has no ID." );
500 [
'job_cmd' => $this->
type,
'job_id' => $id ],
518 if ( !isset(
$params[
'rootJobSignature'] ) ) {
519 throw new MWException(
"Cannot register root job; missing 'rootJobSignature'." );
520 } elseif ( !isset(
$params[
'rootJobTimestamp'] ) ) {
521 throw new MWException(
"Cannot register root job; missing 'rootJobTimestamp'." );
534 $dbw->onTransactionCommitOrIdle(
537 if ( $timestamp && $timestamp >=
$params[
'rootJobTimestamp'] ) {
559 $dbw->delete(
'job', [
'job_cmd' => $this->
type ] );
576 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
577 $lbFactory->waitForReplication( [
578 'domain' => $this->domain,
579 'cluster' => is_string( $this->cluster ) ? $this->cluster :
false
587 foreach ( [
'size',
'acquiredcount' ]
as $type ) {
618 $dbr->select(
'job', self::selectFields(), $conds ),
623 strlen( $row->job_params ) ?
unserialize( $row->job_params ) : []
625 $job->setMetadata(
'id', $row->job_id );
626 $job->setMetadata(
'timestamp', $row->job_timestamp );
641 return is_string( $this->cluster )
642 ?
"DBCluster:{$this->cluster}:{$this->domain}"
643 :
"LBFactory:{$this->domain}";
654 $res =
$dbr->select(
'job',
'DISTINCT job_cmd',
655 [
'job_cmd' => $types ], __METHOD__ );
658 foreach (
$res as $row ) {
659 $types[] = $row->job_cmd;
670 $res =
$dbr->select(
'job', [
'job_cmd',
'COUNT(*) AS count' ],
671 [
'job_cmd' => $types ], __METHOD__, [
'GROUP BY' =>
'job_cmd' ] );
674 foreach (
$res as $row ) {
675 $sizes[$row->job_cmd] = (int)$row->count;
694 if ( !$dbw->lock(
"jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
699 if ( $this->claimTTL > 0 ) {
700 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
704 $res = $dbw->select(
'job',
'job_id',
706 'job_cmd' => $this->
type,
707 "job_token != {$dbw->addQuotes( '' )}",
708 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}",
709 "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ],
715 }, iterator_to_array(
$res )
717 if (
count( $ids ) ) {
724 'job_token_timestamp' => $dbw->timestamp( $now ) ],
729 $affected = $dbw->affectedRows();
736 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
739 "job_token != {$dbw->addQuotes( '' )}",
740 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}"
742 if ( $this->claimTTL > 0 ) {
743 $conds[] =
"job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
747 $res = $dbw->select(
'job',
'job_id', $conds, __METHOD__ );
751 }, iterator_to_array(
$res )
753 if (
count( $ids ) ) {
754 $dbw->delete(
'job', [
'job_id' => $ids ], __METHOD__ );
755 $affected = $dbw->affectedRows();
760 $dbw->unlock(
"jobqueue-recycle-{$this->type}", __METHOD__ );
776 'job_cmd' =>
$job->getType(),
777 'job_namespace' =>
$job->getTitle()->getNamespace(),
778 'job_title' =>
$job->getTitle()->getDBkey(),
782 'job_sha1' => Wikimedia\base_convert(
786 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
818 protected function getDB( $index ) {
820 if ( $this->conn instanceof
IDatabase ) {
822 } elseif ( $this->conn instanceof
DBError ) {
827 $this->conn = Database::factory( $this->
server[
'type'], $this->
server );
828 }
catch ( DBError
$e ) {
835 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
836 $lb = is_string( $this->cluster )
837 ? $lbFactory->getExternalLB( $this->cluster )
838 : $lbFactory->getMainLB( $this->domain );
840 return ( $lb->getServerType( $lb->getWriterIndex() ) !==
'sqlite' )
843 ? $lb->getConnectionRef( $index, [], $this->domain, $lb::CONN_TRX_AUTOCOMMIT )
845 : $lb->getConnectionRef( $index, [], $this->domain );
857 return new ScopedCallback(
function ()
use ( $db, $autoTrx ) {
869 $cluster = is_string( $this->cluster ) ? $this->cluster :
'main';
871 return $this->
cache->makeGlobalKey(
897 if ( (
string)
$blob !==
'' ) {
928 'job_token_timestamp',
doBatchPushInternal(IDatabase $dbw, array $jobs, $flags, $method)
This function should not be called outside of JobQueueDB.
insertFields(IJobSpecification $job, IDatabase $db)
Convenience class for generating iterators from iterators.
doGetSiblingQueuesWithJobs(array $types)
getCoalesceLocationInternal()
Do not use this function outside of JobQueue/JobQueueGroup.
doGetSiblingQueueSizes(array $types)
throwDBException(DBError $e)
set( $key, $value, $ttl=self::TTL_INDEFINITE, array $opts=[])
Set the value of a key in cache.
incrStats( $key, $type, $delta=1)
Call wfIncrStats() for the queue overall and for the queue type.
optimalOrder()
Get the default queue order to use if configuration does not specify one.
__construct(array $params)
Additional parameters include:
getScopedNoTrxFlag(IDatabase $db)
Class to handle job queues stored in the DB.
you have access to all of the normal MediaWiki so you can get a DB use the cache
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getJobIterator(array $conds)
static makeBlob( $params)
supportedOrders()
Get the allowed queue orders for configuration validation.
static newEmpty()
Get an instance that wraps EmptyBagOStuff.
Class to both describe a background job and handle jobs.
namespace and then decline to actually register it file or subcat img or subcat $title
get( $key, &$curTTL=null, array $checkKeys=[], &$info=null)
Fetch the value of a key from cache.
doDeduplicateRootJob(IJobSpecification $job)
recycleAndDeleteStaleJobs()
Recycle or destroy any jobs that have been claimed for too long.
doBatchPush(array $jobs, $flags)
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
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))
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static extractBlob( $blob)
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
string null $cluster
Name of an external DB cluster or null for the local DB cluster.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
static factory( $command, $params=[])
Create the appropriate object to handle a specific job.
Multi-datacenter aware caching interface.
static selectFields()
Return the list of job fields that should be selected.
claimOldest( $uuid)
Reserve a row with a single UPDATE without holding row locks over RTTs...
array null $server
Server configuration array.
unserialize( $serialized)
getRootJobCacheKey( $signature)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
if(count( $args)< 1) $job
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Class to handle enqueueing and running of background jobs.
IDatabase DBError null $conn
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is it should be possible to enable the appropriate rewrite rules by if you can reconfigure the web server
Job queue task description interface.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
claimRandom( $uuid, $rand, $gte)
Reserve a row with a single UPDATE without holding row locks over RTTs...