MediaWiki master
MediaWiki\JobQueue\JobQueue Class Reference

Base class for queueing and running background jobs from a storage backend. More...

Inherited by MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Collaboration diagram for MediaWiki\JobQueue\JobQueue:

Public Member Functions

 ack (RunnableJob $job)
 Acknowledge that a job was completed.
 
 batchPush (array $jobs, $flags=0)
 Push a batch of jobs into the queue.
 
 deduplicateRootJob (IJobSpecification $job)
 Register the "root job" of a given job into the queue for de-duplication.
 
 delayedJobsEnabled ()
 
 delete ()
 Delete all unclaimed and delayed jobs from the queue.
 
 flushCaches ()
 Clear any process and persistent caches.
 
 getAbandonedCount ()
 Get the number of acquired jobs that can no longer be attempted.
 
 getAcquiredCount ()
 Get the number of acquired jobs (these are temporarily out of the queue).
 
 getAllAbandonedJobs ()
 Get an iterator to traverse over all abandoned jobs in this queue.
 
 getAllAcquiredJobs ()
 Get an iterator to traverse over all claimed jobs in this queue.
 
 getAllDelayedJobs ()
 Get an iterator to traverse over all delayed jobs in this queue.
 
 getAllQueuedJobs ()
 Get an iterator to traverse over all available jobs in this queue.
 
 getCoalesceLocationInternal ()
 Do not use this function outside of JobQueue/JobQueueGroup.
 
 getDelayedCount ()
 Get the number of delayed jobs (these are temporarily out of the queue).
 
 getDomain ()
 
 getOrder ()
 
 getReadOnlyReason ()
 
 getSiblingQueueSizes (array $types)
 Check the size of each of the given queues.
 
 getSiblingQueuesWithJobs (array $types)
 Check whether each of the given queues are empty.
 
 getSize ()
 Get the number of available (unacquired, non-delayed) jobs in the queue.
 
 getType ()
 
 isEmpty ()
 Quickly check if the queue has no available (unacquired, non-delayed) jobs.
 
 pop ()
 Pop a job off of the queue.
 
 push ( $jobs, $flags=0)
 Push one or more jobs into the queue.
 
 waitForBackups ()
 Wait for any replica DBs or backup servers to catch up.
 

Static Public Member Functions

static factory (array $params)
 Get a job queue object of the specified type.
 

Protected Member Functions

 __construct (array $params)
 
 assertNotReadOnly ()
 
 doAck (RunnableJob $job)
 
 doBatchPush (array $jobs, $flags)
 
 doDeduplicateRootJob (IJobSpecification $job)
 
 doDelete ()
 
 doFlushCaches ()
 
 doGetAbandonedCount ()
 
 doGetAcquiredCount ()
 
 doGetDelayedCount ()
 
 doGetSiblingQueueSizes (array $types)
 
 doGetSiblingQueuesWithJobs (array $types)
 
 doGetSize ()
 
 doIsEmpty ()
 
 doIsRootJobOldDuplicate (IJobSpecification $job)
 
 doPop ()
 
 doWaitForBackups ()
 
 factoryJob ( $command, $params)
 
 getRootJobCacheKey ( $signature, $type)
 
 incrStats ( $event, $type, $delta=1)
 Call StatsFactory::incrementBy() for the queue overall and for the queue type.
 
 isRootJobOldDuplicate (IJobSpecification $job)
 Check if the "root" job of a given job has been superseded by a newer one.
 
 optimalOrder ()
 Get the default queue order to use if configuration does not specify one.
 
 supportedOrders ()
 Get the allowed queue orders for configuration validation.
 
 supportsDelayedJobs ()
 Find out if delayed jobs are supported for configuration validation.
 
 supportsTypeAgnostic ()
 Subclasses should set this to true if they support type agnostic queues.
 

Protected Attributes

int $claimTTL
 Time to live in seconds.
 
string $domain
 DB domain ID.
 
GlobalIdGenerator $idGenerator
 
int $maxTries
 Maximum number of times to try a job.
 
string $order
 Job priority for pop()
 
string false $readOnlyReason
 Read only rationale (or false if r/w)
 
StatsFactory $stats
 
string $type
 Job type.
 
bool $typeAgnostic
 
WANObjectCache $wanCache
 
const QOS_ATOMIC = 1
 
const ROOTJOB_TTL = 28 * 24 * 3600
 

Detailed Description

Base class for queueing and running background jobs from a storage backend.

See the architecture doc for more information.

Since
1.21
Stability: stable
to extend

Definition at line 50 of file JobQueue.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\JobQueue\JobQueue::__construct ( array $params)
protected
Stability: stable
to call
Parameters
array$params
  • type : A job type, 'default' if typeAgnostic is set
  • domain : A DB domain ID
  • idGenerator : A GlobalIdGenerator instance.
  • wanCache : An instance of WANObjectCache to use for caching [default: none]
  • stats : An instance of StatsFactory [default: none]
  • claimTTL : Seconds a job can be claimed for exclusive execution [default: forever]
  • maxTries : Total times a job can be tried, assuming claims expire [default: 3]
  • order : Queue order, one of ("fifo", "timestamp", "random") [default: variable]
  • readOnlyReason : Mark the queue as read-only with this reason [default: false]
  • typeAgnostic : If the jobqueue should operate agnostic to the job types
    Exceptions
    JobQueueError

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 99 of file JobQueue.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\JobQueue\JobQueue\optimalOrder(), MediaWiki\JobQueue\JobQueue\supportedOrders(), and MediaWiki\JobQueue\JobQueue\supportsTypeAgnostic().

Member Function Documentation

◆ ack()

MediaWiki\JobQueue\JobQueue::ack ( RunnableJob $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.

Parameters
RunnableJob$job
Returns
void
Exceptions
JobQueueError

Definition at line 447 of file JobQueue.php.

References $job, MediaWiki\JobQueue\JobQueue\assertNotReadOnly(), and MediaWiki\JobQueue\JobQueue\doAck().

◆ assertNotReadOnly()

MediaWiki\JobQueue\JobQueue::assertNotReadOnly ( )
protected

◆ batchPush()

MediaWiki\JobQueue\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.

Parameters
IJobSpecification[]$jobs
int$flagsBitfield (supports JobQueue::QOS_ATOMIC)
Returns
void
Exceptions
JobQueueError

Definition at line 372 of file JobQueue.php.

References $job, MediaWiki\JobQueue\JobQueue\assertNotReadOnly(), MediaWiki\JobQueue\JobQueue\deduplicateRootJob(), and MediaWiki\JobQueue\JobQueue\doBatchPush().

Referenced by MediaWiki\JobQueue\JobQueue\push().

◆ deduplicateRootJob()

MediaWiki\JobQueue\JobQueue::deduplicateRootJob ( IJobSpecification $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:

  • rootJobSignature : hash (e.g. SHA1) that identifies the task
  • rootJobTimestamp : TS_MW timestamp of this instance of the task

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 range and leaf job subtypes. Since these jobs include things like page ID ranges and DB primary positions, and can morph into smaller jobs recursively, simple duplicate detection for individual jobs being identical (like that of job_sha1) 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.

Access: internal
For use within JobQueue only
Parameters
IJobSpecification$job
Exceptions
JobQueueError
Returns
bool

Definition at line 492 of file JobQueue.php.

References $job, MediaWiki\JobQueue\JobQueue\assertNotReadOnly(), and MediaWiki\JobQueue\JobQueue\doDeduplicateRootJob().

Referenced by MediaWiki\JobQueue\JobQueue\batchPush().

◆ delayedJobsEnabled()

MediaWiki\JobQueue\JobQueue::delayedJobsEnabled ( )
final
Returns
bool Whether delayed jobs are enabled
Since
1.22

Definition at line 220 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\supportsDelayedJobs().

◆ delete()

MediaWiki\JobQueue\JobQueue::delete ( )
final

Delete all unclaimed and delayed jobs from the queue.

Exceptions
JobQueueError
Since
1.22
Returns
void

Definition at line 585 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\assertNotReadOnly(), and MediaWiki\JobQueue\JobQueue\doDelete().

◆ doAck()

MediaWiki\JobQueue\JobQueue::doAck ( RunnableJob $job)
abstractprotected

◆ doBatchPush()

MediaWiki\JobQueue\JobQueue::doBatchPush ( array $jobs,
$flags )
abstractprotected
See also
JobQueue::batchPush()
Parameters
IJobSpecification[]$jobs
int$flags

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Referenced by MediaWiki\JobQueue\JobQueue\batchPush().

◆ doDeduplicateRootJob()

MediaWiki\JobQueue\JobQueue::doDeduplicateRootJob ( IJobSpecification $job)
protected
Stability: stable
to override
See also
JobQueue::deduplicateRootJob()
Parameters
IJobSpecification$job
Exceptions
JobQueueError
Returns
bool

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 506 of file JobQueue.php.

References $job, and MediaWiki\JobQueue\JobQueue\getRootJobCacheKey().

Referenced by MediaWiki\JobQueue\JobQueue\deduplicateRootJob().

◆ doDelete()

MediaWiki\JobQueue\JobQueue::doDelete ( )
protected
Stability: stable
to override
See also
JobQueue::delete()
Exceptions
JobQueueError

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 596 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\delete().

◆ doFlushCaches()

MediaWiki\JobQueue\JobQueue::doFlushCaches ( )
protected
Stability: stable
to override
See also
JobQueue::flushCaches()
Returns
void

Reimplemented in MediaWiki\JobQueue\JobQueueDB, and MediaWiki\JobQueue\JobQueueFederated.

Definition at line 634 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\flushCaches().

◆ doGetAbandonedCount()

MediaWiki\JobQueue\JobQueue::doGetAbandonedCount ( )
protected
Stability: stable
to override
See also
JobQueue::getAbandonedCount()
Returns
int

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 343 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getAbandonedCount().

◆ doGetAcquiredCount()

MediaWiki\JobQueue\JobQueue::doGetAcquiredCount ( )
abstractprotected

◆ doGetDelayedCount()

MediaWiki\JobQueue\JobQueue::doGetDelayedCount ( )
protected
Stability: stable
to override
See also
JobQueue::getDelayedCount()
Returns
int

Reimplemented in MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 319 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getDelayedCount().

◆ doGetSiblingQueueSizes()

MediaWiki\JobQueue\JobQueue::doGetSiblingQueueSizes ( array $types)
protected
Stability: stable
to override
See also
JobQueue::getSiblingQueuesSize()
Parameters
array$typesList of queues types
Returns
array|null (list of queue types) or null if unsupported

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 741 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getSiblingQueueSizes().

◆ doGetSiblingQueuesWithJobs()

MediaWiki\JobQueue\JobQueue::doGetSiblingQueuesWithJobs ( array $types)
protected
Stability: stable
to override
See also
JobQueue::getSiblingQueuesWithJobs()
Parameters
array$typesList of queues types
Returns
array|null (list of queue types) or null if unsupported

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 717 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getSiblingQueuesWithJobs().

◆ doGetSize()

MediaWiki\JobQueue\JobQueue::doGetSize ( )
abstractprotected

◆ doIsEmpty()

MediaWiki\JobQueue\JobQueue::doIsEmpty ( )
abstractprotected

◆ doIsRootJobOldDuplicate()

MediaWiki\JobQueue\JobQueue::doIsRootJobOldDuplicate ( IJobSpecification $job)
protected
Stability: stable
to override
See also
JobQueue::isRootJobOldDuplicate()
Parameters
IJobSpecification$job
Returns
bool

Reimplemented in MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 545 of file JobQueue.php.

References $job, and MediaWiki\JobQueue\JobQueue\getRootJobCacheKey().

Referenced by MediaWiki\JobQueue\JobQueue\isRootJobOldDuplicate().

◆ doPop()

MediaWiki\JobQueue\JobQueue::doPop ( )
abstractprotected

◆ doWaitForBackups()

MediaWiki\JobQueue\JobQueue::doWaitForBackups ( )
protected
Stability: stable
to override
See also
JobQueue::waitForBackups()
Returns
void

Reimplemented in MediaWiki\JobQueue\JobQueueDB, and MediaWiki\JobQueue\JobQueueFederated.

Definition at line 617 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\waitForBackups().

◆ factory()

static MediaWiki\JobQueue\JobQueue::factory ( array $params)
staticfinal

Get a job queue object of the specified type.

$params includes:

  • class : What job class to use (determines job type)
  • domain : Database domain ID of the wiki the jobs are for (defaults to current wiki)
  • type : The name of the job types this queue handles
  • order : Order that pop() selects jobs, one of "fifo", "timestamp" or "random". If "fifo" is used, the queue will effectively be FIFO. Note that job completion will not appear to be exactly FIFO if there are multiple job runners since jobs can take different times to finish once popped. If "timestamp" is used, the queue will at least be loosely ordered by timestamp, allowing for some jobs to be popped off out of order. If "random" is used, pop() will pick jobs in random order. Note that it may only be weakly random (e.g. a lottery of the oldest X). If "any" is chosen, the queue will use whatever order is the fastest. This might be useful for improving concurrency for job acquisition.
  • claimTTL : If supported, the queue will recycle jobs that have been popped but not acknowledged as completed after this many seconds. Recycling of jobs simply means re-inserting them into the queue. Jobs can be attempted up to three times before being discarded.
  • readOnlyReason : Set this to a string to make the queue read-only. [optional]
  • idGenerator : A GlobalIdGenerator instance.
  • stats : A StatsFactory. [optional]

Queue classes should throw an exception if they do not support the options given.

Parameters
array$params
Returns
JobQueue
Exceptions
JobQueueError

Definition at line 157 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueueFederated\__construct(), MediaWiki\JobQueue\JobQueueGroup\get(), and MediaWiki\JobQueue\JobQueueGroup\getCoalescedQueues().

◆ factoryJob()

MediaWiki\JobQueue\JobQueue::factoryJob ( $command,
$params )
protected

◆ flushCaches()

MediaWiki\JobQueue\JobQueue::flushCaches ( )
final

Clear any process and persistent caches.

Returns
void

Definition at line 625 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doFlushCaches().

◆ getAbandonedCount()

MediaWiki\JobQueue\JobQueue::getAbandonedCount ( )
final

Get the number of acquired jobs that can no longer be attempted.

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.

Returns
int
Exceptions
JobQueueError

Definition at line 332 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetAbandonedCount().

◆ getAcquiredCount()

MediaWiki\JobQueue\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.

Returns
int
Exceptions
JobQueueError

Definition at line 286 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetAcquiredCount().

Referenced by MediaWiki\JobQueue\JobQueueMemory\doAck().

◆ getAllAbandonedJobs()

MediaWiki\JobQueue\JobQueue::getAllAbandonedJobs ( )

Get an iterator to traverse over all abandoned jobs in this queue.

Stability: stable
to override
Returns
\Iterator<RunnableJob>
Exceptions
JobQueueError
Since
1.25

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 683 of file JobQueue.php.

◆ getAllAcquiredJobs()

MediaWiki\JobQueue\JobQueue::getAllAcquiredJobs ( )

Get an iterator to traverse over all claimed jobs in this queue.

Callers should be quick to iterator over it or few results will be returned due to jobs being acknowledged and deleted

Stability: stable
to override
Returns
\Iterator<RunnableJob>
Exceptions
JobQueueError
Since
1.26

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 671 of file JobQueue.php.

◆ getAllDelayedJobs()

MediaWiki\JobQueue\JobQueue::getAllDelayedJobs ( )

Get an iterator to traverse over all delayed jobs in this queue.

Note: results may be stale if the queue is concurrently modified.

Stability: stable
to override
Returns
\Iterator<RunnableJob>
Exceptions
JobQueueError
Since
1.22

Reimplemented in MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 656 of file JobQueue.php.

◆ getAllQueuedJobs()

MediaWiki\JobQueue\JobQueue::getAllQueuedJobs ( )
abstract

Get an iterator to traverse over all available jobs in this queue.

This does not include jobs that are currently acquired or delayed. Note: results may be stale if the queue is concurrently modified.

Returns
\Iterator<RunnableJob>
Exceptions
JobQueueError

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

◆ getCoalesceLocationInternal()

MediaWiki\JobQueue\JobQueue::getCoalesceLocationInternal ( )

Do not use this function outside of JobQueue/JobQueueGroup.

Stability: stable
to override
Returns
string|null
Since
1.22

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 694 of file JobQueue.php.

◆ getDelayedCount()

MediaWiki\JobQueue\JobQueue::getDelayedCount ( )
final

Get the number of delayed 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.

Returns
int
Exceptions
JobQueueError
Since
1.22

Definition at line 308 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetDelayedCount().

◆ getDomain()

MediaWiki\JobQueue\JobQueue::getDomain ( )
final
Returns
string Database domain ID

Definition at line 174 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\$domain.

◆ getOrder()

MediaWiki\JobQueue\JobQueue::getOrder ( )
final
Returns
string One of (random, timestamp, fifo, undefined)

Definition at line 188 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\$order.

◆ getReadOnlyReason()

MediaWiki\JobQueue\JobQueue::getReadOnlyReason ( )
Returns
string|false Read-only rational or false if r/w
Since
1.27

Definition at line 228 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\$readOnlyReason.

◆ getRootJobCacheKey()

MediaWiki\JobQueue\JobQueue::getRootJobCacheKey ( $signature,
$type )
protected

◆ getSiblingQueueSizes()

MediaWiki\JobQueue\JobQueue::getSiblingQueueSizes ( array $types)
final

Check the size of each of the given queues.

For queues not served by the same store as this one, 0 is returned. This is used for batching checks for queues stored at the same place.

Parameters
array$typesList of queues types
Returns
array|null (job type => whether queue is empty) or null if unsupported
Exceptions
JobQueueError
Since
1.22

Definition at line 731 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetSiblingQueueSizes().

◆ getSiblingQueuesWithJobs()

MediaWiki\JobQueue\JobQueue::getSiblingQueuesWithJobs ( array $types)
final

Check whether each of the given queues are empty.

This is used for batching checks for queues stored at the same place.

Parameters
array$typesList of queues types
Returns
array|null (list of non-empty queue types) or null if unsupported
Exceptions
JobQueueError
Since
1.22

Definition at line 707 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetSiblingQueuesWithJobs().

◆ getSize()

MediaWiki\JobQueue\JobQueue::getSize ( )
final

Get the number of available (unacquired, non-delayed) 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.

Returns
int
Exceptions
JobQueueError

Definition at line 265 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doGetSize().

◆ getType()

MediaWiki\JobQueue\JobQueue::getType ( )
final

◆ incrStats()

MediaWiki\JobQueue\JobQueue::incrStats ( $event,
$type,
$delta = 1 )
protected

◆ isEmpty()

MediaWiki\JobQueue\JobQueue::isEmpty ( )
final

Quickly check if the queue has no available (unacquired, non-delayed) 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 effect is typically not distinguishable from the race condition between isEmpty() and pop().

Returns
bool
Exceptions
JobQueueError

Definition at line 244 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doIsEmpty().

◆ isRootJobOldDuplicate()

MediaWiki\JobQueue\JobQueue::isRootJobOldDuplicate ( IJobSpecification $job)
finalprotected

Check if the "root" job of a given job has been superseded by a newer one.

Parameters
IJobSpecification$job
Exceptions
JobQueueError
Returns
bool

Definition at line 533 of file JobQueue.php.

References $job, and MediaWiki\JobQueue\JobQueue\doIsRootJobOldDuplicate().

Referenced by MediaWiki\JobQueue\JobQueue\pop().

◆ optimalOrder()

MediaWiki\JobQueue\JobQueue::optimalOrder ( )
abstractprotected

Get the default queue order to use if configuration does not specify one.

Returns
string One of (random, timestamp, fifo, undefined)

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Referenced by MediaWiki\JobQueue\JobQueue\__construct().

◆ pop()

MediaWiki\JobQueue\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.

Exceptions
JobQueueError
Returns
RunnableJob|false Returns false if there are no jobs

Definition at line 411 of file JobQueue.php.

References $job, MediaWiki\JobQueue\JobQueue\assertNotReadOnly(), MediaWiki\JobQueue\JobQueue\doPop(), MediaWiki\JobQueue\JobQueue\incrStats(), and MediaWiki\JobQueue\JobQueue\isRootJobOldDuplicate().

◆ push()

MediaWiki\JobQueue\JobQueue::push ( $jobs,
$flags = 0 )
final

Push one or more 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.

Parameters
IJobSpecification | IJobSpecification[]$jobs
int$flagsBitfield (supports JobQueue::QOS_ATOMIC)
Returns
void
Exceptions
JobQueueError

Definition at line 357 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\batchPush().

Referenced by CopyJobQueue\copyJobs().

◆ supportedOrders()

MediaWiki\JobQueue\JobQueue::supportedOrders ( )
abstractprotected

Get the allowed queue orders for configuration validation.

Returns
array Subset of (random, timestamp, fifo, undefined)

Reimplemented in MediaWiki\JobQueue\JobQueueDB, MediaWiki\JobQueue\JobQueueFederated, MediaWiki\JobQueue\JobQueueMemory, and MediaWiki\JobQueue\JobQueueRedis.

Referenced by MediaWiki\JobQueue\JobQueue\__construct().

◆ supportsDelayedJobs()

MediaWiki\JobQueue\JobQueue::supportsDelayedJobs ( )
protected

Find out if delayed jobs are supported for configuration validation.

Stability: stable
to override
Returns
bool Whether delayed jobs are supported

Reimplemented in MediaWiki\JobQueue\JobQueueFederated, and MediaWiki\JobQueue\JobQueueRedis.

Definition at line 212 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\delayedJobsEnabled().

◆ supportsTypeAgnostic()

MediaWiki\JobQueue\JobQueue::supportsTypeAgnostic ( )
protected

Subclasses should set this to true if they support type agnostic queues.

Returns
bool
Since
1.38

Definition at line 798 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\__construct().

◆ waitForBackups()

MediaWiki\JobQueue\JobQueue::waitForBackups ( )
final

Wait for any replica DBs or backup servers to catch up.

This does nothing for certain queue classes.

Returns
void
Exceptions
JobQueueError

Definition at line 608 of file JobQueue.php.

References MediaWiki\JobQueue\JobQueue\doWaitForBackups().

Referenced by CopyJobQueue\copyJobs().

Member Data Documentation

◆ $claimTTL

int MediaWiki\JobQueue\JobQueue::$claimTTL
protected

Time to live in seconds.

Definition at line 58 of file JobQueue.php.

◆ $domain

string MediaWiki\JobQueue\JobQueue::$domain
protected

◆ $idGenerator

GlobalIdGenerator MediaWiki\JobQueue\JobQueue::$idGenerator
protected

Definition at line 66 of file JobQueue.php.

◆ $maxTries

int MediaWiki\JobQueue\JobQueue::$maxTries
protected

Maximum number of times to try a job.

Definition at line 60 of file JobQueue.php.

◆ $order

string MediaWiki\JobQueue\JobQueue::$order
protected

Job priority for pop()

Definition at line 56 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getOrder().

◆ $readOnlyReason

string false MediaWiki\JobQueue\JobQueue::$readOnlyReason
protected

Read only rationale (or false if r/w)

Definition at line 62 of file JobQueue.php.

Referenced by MediaWiki\JobQueue\JobQueue\getReadOnlyReason().

◆ $stats

StatsFactory MediaWiki\JobQueue\JobQueue::$stats
protected

Definition at line 64 of file JobQueue.php.

◆ $type

◆ $typeAgnostic

bool MediaWiki\JobQueue\JobQueue::$typeAgnostic
protected

Definition at line 72 of file JobQueue.php.

◆ $wanCache

WANObjectCache MediaWiki\JobQueue\JobQueue::$wanCache
protected

Definition at line 69 of file JobQueue.php.

◆ QOS_ATOMIC

const MediaWiki\JobQueue\JobQueue::QOS_ATOMIC = 1
protected

Definition at line 77 of file JobQueue.php.

◆ ROOTJOB_TTL

const MediaWiki\JobQueue\JobQueue::ROOTJOB_TTL = 28 * 24 * 3600
protected

Definition at line 80 of file JobQueue.php.


The documentation for this class was generated from the following file: