MediaWiki
REL1_21
|
Class to handle enqueueing and running of background jobs. More...
Public Member Functions | |
ack (Job $job) | |
Acknowledge that a job was completed. | |
batchPush (array $jobs, $flags=0) | |
Push a batch of jobs into the queue. | |
deduplicateRootJob (Job $job) | |
Register the "root job" of a given job into the queue for de-duplication. | |
flushCaches () | |
Clear any process and persistent caches. | |
getAcquiredCount () | |
Get the number of acquired jobs (these are temporarily out of the queue). | |
getAllQueuedJobs () | |
Get an iterator to traverse over all of the jobs in this queue. | |
getOrder () | |
getPeriodicTasks () | |
Return a map of task names to task definition maps. | |
getSize () | |
Get the number of available (unacquired) jobs in the queue. | |
getType () | |
getWiki () | |
isEmpty () | |
Quickly check if the queue is empty (has no available jobs). | |
pop () | |
Pop a job off of the queue. | |
push ($jobs, $flags=0) | |
Push a single jobs into the queue. | |
setTestingPrefix ($key) | |
Namespace the queue with a key to isolate it for testing. | |
waitForBackups () | |
Wait for any slaves or backup servers to catch up. | |
Static Public Member Functions | |
static | factory (array $params) |
Get a job queue object of the specified type. | |
Public Attributes | |
const | QoS_Atomic = 1 |
Protected Member Functions | |
__construct (array $params) | |
doAck (Job $job) | |
doBatchPush (array $jobs, $flags) | |
doDeduplicateRootJob (Job $job) | |
doFlushCaches () | |
doGetAcquiredCount () | |
doGetPeriodicTasks () | |
doGetSize () | |
doIsEmpty () | |
doPop () | |
doWaitForBackups () | |
optimalOrder () | |
supportedOrders () | |
Protected Attributes | |
$claimTTL | |
$maxTries | |
$order | |
$type | |
$wiki |
Class to handle enqueueing and running of background jobs.
Definition at line 31 of file JobQueue.php.
JobQueue::__construct | ( | array $ | params | ) | [protected] |
$params | array |
Reimplemented in JobQueueDB.
Definition at line 43 of file JobQueue.php.
References optimalOrder(), order, supportedOrders(), type, and wiki.
JobQueue::ack | ( | Job $ | job | ) | [final] |
Acknowledge that a job was completed.
This does nothing for certain queue classes or if "claimTTL" is not set. Outside callers should use JobQueueGroup::ack() instead of this function.
$job | Job |
MWException |
Definition at line 284 of file JobQueue.php.
References $ok, doAck(), Job\getType(), type, wfProfileIn(), and wfProfileOut().
JobQueue::batchPush | ( | array $ | jobs, |
$ | flags = 0 |
||
) | [final] |
Push a batch of jobs into the queue.
This does not require $wgJobClasses to be set for the given job type. Outside callers should use JobQueueGroup::push() instead of this function.
array | $jobs | List of Jobs |
$flags | integer Bitfield (supports JobQueue::QoS_Atomic) |
MWException |
Definition at line 221 of file JobQueue.php.
References $flags, $job, $ok, as, doBatchPush(), type, wfProfileIn(), and wfProfileOut().
Referenced by push().
JobQueue::deduplicateRootJob | ( | Job $ | job | ) | [final] |
Register the "root job" of a given job into the queue for de-duplication.
This should only be called right *after* all the new jobs have been inserted. This is used to turn older, duplicate, job entries into no-ops. The root job information will remain in the registry until it simply falls out of cache.
This requires that $job has two special fields in the "params" array:
A "root job" is a conceptual job that consist of potentially many smaller jobs that are actually inserted into the queue. For example, "refreshLinks" jobs are spawned when a template is edited. One can think of the task as "update links of pages that use template X" and an instance of that task as a "root job". However, what actually goes into the queue are potentially many refreshLinks2 jobs. Since these jobs include things like page ID ranges and DB master positions, and morph into smaller refreshLinks2 jobs recursively, simple duplicate detection (like job_sha1) for individual jobs being identical is not useful.
In the case of "refreshLinks", if these jobs are still in the queue when the template is edited again, we want all of these old refreshLinks jobs for that template to become no-ops. This can greatly reduce server load, since refreshLinks jobs involves parsing. Essentially, the new batch of jobs belong to a new "root job" and the older ones to a previous "root job" for the same task of "update links of pages that use template X".
This does nothing for certain queue classes.
$job | Job |
MWException |
Definition at line 331 of file JobQueue.php.
References $ok, doDeduplicateRootJob(), Job\getType(), type, wfProfileIn(), and wfProfileOut().
JobQueue::doAck | ( | Job $ | job | ) | [abstract, protected] |
JobQueue::doBatchPush | ( | array $ | jobs, |
$ | flags | ||
) | [abstract, protected] |
JobQueue::doDeduplicateRootJob | ( | Job $ | job | ) | [protected] |
$job | Job |
Reimplemented in JobQueueDB.
Definition at line 346 of file JobQueue.php.
Referenced by deduplicateRootJob().
JobQueue::doFlushCaches | ( | ) | [protected] |
Reimplemented in JobQueueDB.
Definition at line 413 of file JobQueue.php.
Referenced by flushCaches().
JobQueue::doGetAcquiredCount | ( | ) | [abstract, protected] |
Reimplemented in JobQueueDB.
Referenced by getAcquiredCount().
JobQueue::doGetPeriodicTasks | ( | ) | [protected] |
Reimplemented in JobQueueDB.
Definition at line 394 of file JobQueue.php.
References array().
Referenced by getPeriodicTasks().
JobQueue::doGetSize | ( | ) | [abstract, protected] |
JobQueue::doIsEmpty | ( | ) | [abstract, protected] |
JobQueue::doPop | ( | ) | [abstract, protected] |
JobQueue::doWaitForBackups | ( | ) | [protected] |
Reimplemented in JobQueueDB.
Definition at line 368 of file JobQueue.php.
Referenced by waitForBackups().
static JobQueue::factory | ( | array $ | params | ) | [static, final] |
Get a job queue object of the specified type.
$params includes:
Queue classes should throw an exception if they do not support the options given.
$params | array |
MWException |
Definition at line 85 of file JobQueue.php.
References MWInit\classExists().
Referenced by JobQueueDB\doPop(), JobQueueDB\getAllQueuedJobs(), and JobQueueTest\setUp().
JobQueue::flushCaches | ( | ) | [final] |
Clear any process and persistent caches.
Definition at line 403 of file JobQueue.php.
References doFlushCaches(), wfProfileIn(), and wfProfileOut().
JobQueue::getAcquiredCount | ( | ) | [final] |
Get the number of acquired jobs (these are temporarily out of the queue).
Queue classes should use caching if they are any slower without memcached.
If caching is used, this number might be out of date for a minute.
MWException |
Definition at line 184 of file JobQueue.php.
References $res, doGetAcquiredCount(), wfProfileIn(), and wfProfileOut().
JobQueue::getAllQueuedJobs | ( | ) | [abstract] |
Get an iterator to traverse over all of the jobs in this queue.
This does not include jobs that are current acquired. In general, this should only be called on a queue that is no longer being popped.
MWException |
Reimplemented in JobQueueDB.
JobQueue::getOrder | ( | ) | [final] |
Definition at line 114 of file JobQueue.php.
References order.
JobQueue::getPeriodicTasks | ( | ) | [final] |
Return a map of task names to task definition maps.
A "task" is a fast periodic queue maintenance action. Mutually exclusive tasks must implement their own locking in the callback.
Each task value is an associative array with:
Definition at line 382 of file JobQueue.php.
References $name, as, and doGetPeriodicTasks().
JobQueue::getSize | ( | ) | [final] |
Get the number of available (unacquired) jobs in the queue.
Queue classes should use caching if they are any slower without memcached.
If caching is used, this number might be out of date for a minute.
MWException |
Definition at line 162 of file JobQueue.php.
References $res, doGetSize(), wfProfileIn(), and wfProfileOut().
JobQueue::getType | ( | ) | [final] |
Definition at line 107 of file JobQueue.php.
References type.
Referenced by JobQueueDB\getAllQueuedJobs().
JobQueue::getWiki | ( | ) | [final] |
JobQueue::isEmpty | ( | ) | [final] |
Quickly check if the queue is empty (has no available jobs).
Queue classes should use caching if they are any slower without memcached.
If caching is used, this might return false when there are actually no jobs. If pop() is called and returns false then it should correct the cache. Also, calling flushCaches() first prevents this. However, this affect is typically not distinguishable from the race condition between isEmpty() and pop().
MWException |
Definition at line 140 of file JobQueue.php.
References $res, doIsEmpty(), wfProfileIn(), and wfProfileOut().
JobQueue::optimalOrder | ( | ) | [abstract, protected] |
Reimplemented in JobQueueDB.
Referenced by __construct().
JobQueue::pop | ( | ) | [final] |
Pop a job off of the queue.
This requires $wgJobClasses to be set for the given job type. Outside callers should use JobQueueGroup::pop() instead of this function.
MWException |
Definition at line 252 of file JobQueue.php.
References $job, doPop(), global, type, wfProfileIn(), wfProfileOut(), wfWikiID(), and wiki.
JobQueue::push | ( | $ | jobs, |
$ | flags = 0 |
||
) | [final] |
Push a single jobs into the queue.
This does not require $wgJobClasses to be set for the given job type. Outside callers should use JobQueueGroup::push() instead of this function.
$jobs | Job|Array |
$flags | integer Bitfield (supports JobQueue::QoS_Atomic) |
MWException |
Definition at line 207 of file JobQueue.php.
References $flags, array(), and batchPush().
JobQueue::setTestingPrefix | ( | $ | key | ) |
Namespace the queue with a key to isolate it for testing.
$key | string |
MWException |
Definition at line 432 of file JobQueue.php.
JobQueue::supportedOrders | ( | ) | [abstract, protected] |
Reimplemented in JobQueueDB.
Referenced by __construct().
JobQueue::waitForBackups | ( | ) | [final] |
Wait for any slaves or backup servers to catch up.
This does nothing for certain queue classes.
MWException |
Definition at line 358 of file JobQueue.php.
References doWaitForBackups(), wfProfileIn(), and wfProfileOut().
JobQueue::$claimTTL [protected] |
Definition at line 35 of file JobQueue.php.
JobQueue::$maxTries [protected] |
Definition at line 36 of file JobQueue.php.
JobQueue::$order [protected] |
Definition at line 34 of file JobQueue.php.
JobQueue::$type [protected] |
Definition at line 33 of file JobQueue.php.
Referenced by JobQueueDB\doFlushCaches().
JobQueue::$wiki [protected] |
Definition at line 32 of file JobQueue.php.
const JobQueue::QoS_Atomic = 1 |
Definition at line 38 of file JobQueue.php.
Referenced by JobQueueDB\doBatchPush().