Go to the documentation of this file.
56 $this->cluster = isset(
$params[
'cluster'] ) ?
$params[
'cluster'] :
false;
62 return array(
'random',
'timestamp',
'fifo' );
76 $isEmpty = $this->
cache->get( $key );
77 if ( $isEmpty ===
'true' ) {
79 } elseif ( $isEmpty ===
'false' ) {
85 $found =
$dbr->selectField(
86 'job',
'1',
array(
'job_cmd' => $this->
type,
'job_token' =>
'' ), __METHOD__
91 $this->
cache->add( $key, $found ?
'false' :
'true', self::CACHE_TTL_LONG );
104 if ( is_int(
$size ) ) {
110 $size = (int)
$dbr->selectField(
'job',
'COUNT(*)',
111 array(
'job_cmd' => $this->
type,
'job_token' =>
'' ),
117 $this->
cache->set( $key,
$size, self::CACHE_TTL_SHORT );
127 if ( $this->claimTTL <= 0 ) {
140 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
141 array(
'job_cmd' => $this->
type,
"job_token != {$dbr->addQuotes( '' )}" ),
147 $this->
cache->set( $key,
$count, self::CACHE_TTL_SHORT );
160 if ( $this->claimTTL <= 0 ) {
166 $count = $wgMemc->get( $key );
173 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
175 'job_cmd' => $this->
type,
176 "job_token != {$dbr->addQuotes( '' )}",
177 "job_attempts >= " .
$dbr->addQuotes( $this->maxTries )
200 $method = __METHOD__;
201 $dbw->onTransactionIdle(
202 function () use ( $dbw, $that, $jobs,
$flags, $method ) {
203 $that->doBatchPushInternal( $dbw, $jobs,
$flags, $method );
221 if ( !count( $jobs ) ) {
227 foreach ( $jobs
as $job ) {
229 if (
$job->ignoreDuplicates() ) {
230 $rowSet[$row[
'job_sha1']] = $row;
236 if (
$flags & self::QOS_ATOMIC ) {
237 $dbw->begin( $method );
241 if ( count( $rowSet ) ) {
242 $res = $dbw->select(
'job',
'job_sha1',
245 'job_sha1' => array_keys( $rowSet ),
250 foreach (
$res as $row ) {
251 wfDebug(
"Job with hash '{$row->job_sha1}' is a duplicate.\n" );
252 unset( $rowSet[$row->job_sha1] );
256 $rows = array_merge( $rowList, array_values( $rowSet ) );
258 foreach ( array_chunk( $rows, 50 )
as $rowBatch ) {
259 $dbw->insert(
'job', $rowBatch, $method );
263 'job-insert-duplicate',
265 count( $rowSet ) + count( $rowList ) - count( $rows ),
269 if (
$flags & self::QOS_ATOMIC ) {
270 $dbw->rollback( $method );
274 if (
$flags & self::QOS_ATOMIC ) {
275 $dbw->commit( $method );
287 protected function doPop() {
288 if ( $this->
cache->get( $this->getCacheKey(
'empty' ) ) ===
'true' ) {
294 $dbw->commit( __METHOD__,
'flush' );
295 $autoTrx = $dbw->getFlag(
DBO_TRX );
297 $scopedReset =
new ScopedCallback(
function () use ( $dbw, $autoTrx ) {
298 $dbw->setFlag( $autoTrx ?
DBO_TRX : 0 );
305 if ( in_array( $this->
order,
array(
'fifo',
'timestamp' ) ) ) {
308 $rand = mt_rand( 0, self::MAX_JOB_RANDOM );
309 $gte = (bool)mt_rand( 0, 1 );
314 $this->
cache->set( $this->
getCacheKey(
'empty' ),
'true', self::CACHE_TTL_LONG );
321 $dbw->delete(
'job',
array(
'job_id' => $row->job_id ), __METHOD__ );
322 wfDebug(
"Row has invalid title '{$row->job_title}'.\n" );
326 self::extractBlob( $row->job_params ), $row->job_id );
327 $job->metadata[
'id'] = $row->job_id;
345 protected function claimRandom( $uuid, $rand, $gte ) {
351 $invertedDirection =
false;
360 $ineq = $gte ?
'>=' :
'<=';
361 $dir = $gte ?
'ASC' :
'DESC';
362 $row = $dbw->selectRow(
'job', self::selectFields(),
364 'job_cmd' => $this->
type,
366 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
368 array(
'ORDER BY' =>
"job_random {$dir}" )
370 if ( !$row && !$invertedDirection ) {
372 $invertedDirection =
true;
379 $row = $dbw->selectRow(
'job', self::selectFields(),
381 'job_cmd' => $this->
type,
385 array(
'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
397 'job_token' => $uuid,
398 'job_token_timestamp' => $dbw->timestamp(),
399 'job_attempts = job_attempts+1' ),
400 array(
'job_cmd' => $this->
type,
'job_id' => $row->job_id,
'job_token' =>
'' ),
405 if ( !$dbw->affectedRows() ) {
427 if ( $dbw->getType() ===
'mysql' ) {
432 $dbw->query(
"UPDATE {$dbw->tableName( 'job' )} " .
434 "job_token = {$dbw->addQuotes( $uuid ) }, " .
435 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
436 "job_attempts = job_attempts+1 " .
438 "job_cmd = {$dbw->addQuotes( $this->type )} " .
439 "AND job_token = {$dbw->addQuotes( '' )} " .
440 ") ORDER BY job_id ASC LIMIT 1",
448 'job_token' => $uuid,
449 'job_token_timestamp' => $dbw->timestamp(),
450 'job_attempts = job_attempts+1' ),
451 array(
'job_id = (' .
452 $dbw->selectSQLText(
'job',
'job_id',
453 array(
'job_cmd' => $this->
type,
'job_token' =>
'' ),
455 array(
'ORDER BY' =>
'job_id ASC',
'LIMIT' => 1 ) ) .
462 if ( $dbw->affectedRows() ) {
463 $row = $dbw->selectRow(
'job', self::selectFields(),
464 array(
'job_cmd' => $this->
type,
'job_token' => $uuid ), __METHOD__
467 wfDebug(
"Row deleted as duplicate by another process.\n" );
484 if ( !isset(
$job->metadata[
'id'] ) ) {
485 throw new MWException(
"Job of type '{$job->getType()}' has no ID." );
490 $dbw->commit( __METHOD__,
'flush' );
491 $autoTrx = $dbw->getFlag(
DBO_TRX );
493 $scopedReset =
new ScopedCallback(
function () use ( $dbw, $autoTrx ) {
494 $dbw->setFlag( $autoTrx ?
DBO_TRX : 0 );
499 array(
'job_cmd' => $this->
type,
'job_id' => $job->metadata[
'id'] ), __METHOD__ );
515 if ( !isset(
$params[
'rootJobSignature'] ) ) {
516 throw new MWException(
"Cannot register root job; missing 'rootJobSignature'." );
517 } elseif ( !isset(
$params[
'rootJobTimestamp'] ) ) {
518 throw new MWException(
"Cannot register root job; missing 'rootJobTimestamp'." );
528 $dbw->onTransactionIdle(
function () use (
$cache,
$params, $key, $dbw ) {
548 $dbw->delete(
'job',
array(
'job_cmd' => $this->
type ) );
569 'recycleAndDeleteStaleJobs' =>
array(
570 'callback' =>
array( $this,
'recycleAndDeleteStaleJobs' ),
571 'period' => ceil( $this->claimTTL / 2 )
580 foreach (
array(
'empty',
'size',
'acquiredcount' )
as $type ) {
593 $dbr->select(
'job', self::selectFields(),
594 array(
'job_cmd' => $this->
getType(),
'job_token' =>
'' ) ),
595 function ( $row ) use (
$dbr ) {
599 strlen( $row->job_params ) ? unserialize( $row->job_params ) :
false
601 $job->metadata[
'id'] = $row->job_id;
611 return $this->cluster
612 ?
"DBCluster:{$this->cluster}:{$this->wiki}"
613 :
"LBFactory:{$this->wiki}";
618 $res =
$dbr->select(
'job',
'DISTINCT job_cmd',
619 array(
'job_cmd' => $types ), __METHOD__ );
622 foreach (
$res as $row ) {
623 $types[] = $row->job_cmd;
631 $res =
$dbr->select(
'job',
array(
'job_cmd',
'COUNT(*) AS count' ),
632 array(
'job_cmd' => $types ), __METHOD__,
array(
'GROUP BY' =>
'job_cmd' ) );
635 foreach (
$res as $row ) {
636 $sizes[$row->job_cmd] = (int)$row->count;
653 if ( !$dbw->lock(
"jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
658 if ( $this->claimTTL > 0 ) {
659 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
663 $res = $dbw->select(
'job',
'job_id',
665 'job_cmd' => $this->
type,
666 "job_token != {$dbw->addQuotes( '' )}",
667 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}",
668 "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ),
674 }, iterator_to_array(
$res )
676 if ( count( $ids ) ) {
683 'job_token_timestamp' => $dbw->timestamp( $now ) ),
688 $affected = $dbw->affectedRows();
691 $this->
cache->set( $this->
getCacheKey(
'empty' ),
'false', self::CACHE_TTL_LONG );
696 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
698 'job_cmd' => $this->
type,
699 "job_token != {$dbw->addQuotes( '' )}",
700 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}"
702 if ( $this->claimTTL > 0 ) {
703 $conds[] =
"job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
707 $res = $dbw->select(
'job',
'job_id', $conds, __METHOD__ );
711 }, iterator_to_array(
$res )
713 if ( count( $ids ) ) {
714 $dbw->delete(
'job',
array(
'job_id' => $ids ), __METHOD__ );
715 $affected = $dbw->affectedRows();
720 $dbw->unlock(
"jobqueue-recycle-{$this->type}", __METHOD__ );
738 'job_namespace' =>
$job->getTitle()->getNamespace(),
739 'job_title' =>
$job->getTitle()->getDBkey(),
742 'job_id' => $dbw->nextSequenceValue(
'job_job_id_seq' ),
743 'job_timestamp' => $dbw->timestamp(),
745 sha1( serialize(
$job->getDeduplicationInfo() ) ),
748 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
780 protected function getDB( $index ) {
785 return $lb->getConnectionRef( $index,
array(), $this->
wiki );
794 $cluster = is_string( $this->cluster ) ? $this->cluster :
'main';
816 if ( (
string)
$blob !==
'' ) {
817 return unserialize(
$blob );
847 'job_token_timestamp',
doBatchPushInternal(IDatabase $dbw, array $jobs, $flags, $method)
This function should not be called outside of JobQueueDB.
Convenience class for generating iterators from iterators.
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
doGetSiblingQueuesWithJobs(array $types)
getCoalesceLocationInternal()
Do not use this function outside of JobQueue/JobQueueGroup.
doGetSiblingQueueSizes(array $types)
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
static incrStats( $key, $type, $delta=1, $wiki=null)
Call wfIncrStats() for the queue overall and for the queue type.
throwDBException(DBError $e)
A BagOStuff object with no objects in it.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
wfGetLB( $wiki=false)
Get a load balancer object.
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
optimalOrder()
Get the default queue order to use if configuration does not specify one.
__construct(array $params)
Additional parameters include:
interface is intended to be more or less compatible with the PHP memcached client.
wfSplitWikiID( $wiki)
Split a wiki ID into DB name and table prefix.
insertFields(IJobSpecification $job)
Class to handle job queues stored in the DB.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
you have access to all of the normal MediaWiki so you can get a DB use the cache
static makeBlob( $params)
set( $key, $value, $exptime=0)
Set an item.
supportedOrders()
Get the allowed queue orders for configuration validation.
Class to both describe a background job and handle jobs.
get( $key, &$casToken=null)
Get an item with the given key.
if( $wgAPIRequestLog) $lb
recycleAndDeleteStaleJobs()
Recycle or destroy any jobs that have been claimed for too long.
doBatchPush(array $jobs, $flags)
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
doDeduplicateRootJob(Job $job)
when a variable name is used in a it is silently declared as a new masking the global
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
wfForeignMemcKey( $db, $prefix)
Get a cache key for a foreign DB.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
processing should stop and the error should be shown to the user * false
static extractBlob( $blob)
Database error base class.
Class for asserting that a callback happens when an dummy object leaves scope.
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
presenting them properly to the user as errors is done by the caller $title
static factory( $command, Title $title, $params=false)
Create the appropriate object to handle a specific job.
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...
Interface for classes that implement or wrap DatabaseBase.
Class to store objects in the database.
getRootJobCacheKey( $signature)
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
& wfGetLBFactory()
Get the load balancer factory object.
if(count( $args)==0) $dir
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
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.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any order
Job queue task description interface.
bool string $cluster
Name of an external DB cluster.
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...