MediaWiki  master
Job Class Reference

Class to both describe a background job and handle jobs. More...

Inheritance diagram for Job:
Collaboration diagram for Job:

Public Member Functions

 __construct ( $command, $params=null)
 Stable to call. More...
 
 allowRetries ()
 
Returns
bool Whether this job can be retried on failure by job runners
Since
1.21
Stable to override More...
 
 getDeduplicationInfo ()
 Subclasses may need to override this to make duplication detection work. More...
 
 getLastError ()
 
Returns
string
Stable to override More...
 
 getMetadata ( $field=null)
 Stable to override. More...
 
 getParams ()
 
Returns
array Parameters that specify sources, targets, and options for execution
Stable to override More...
 
 getQueuedTimestamp ()
 
 getReadyTimestamp ()
 
Returns
int|null UNIX timestamp of when the job was runnable, or null
Since
1.26
Stable to override More...
 
 getReleaseTimestamp ()
 Stable to override. More...
 
 getRequestId ()
 
Returns
string|null Id of the request that created this job. Follows jobs recursively, allowing to track the id of the request that started a job when jobs insert jobs which insert other jobs.
Since
1.27
Stable to override More...
 
 getRootJobParams ()
 Stable to override. More...
 
 getTitle ()
 
 getType ()
 
Returns
string Job type that defines what sort of changes this job makes
Stable to override More...
 
 hasExecutionFlag ( $flag)
 
Parameters
int$flagJOB_* class constant
Returns
bool
Since
1.31
Stable to override More...
 
 hasRootJobParams ()
 Stable to override. More...
 
 ignoreDuplicates ()
 Whether the queue should reject insertion of this job if a duplicate exists. More...
 
 isRootJob ()
 Stable to override. More...
 
 setMetadata ( $field, $value)
 Stable to override. More...
 
 teardown ( $status)
 Stable to override More...
 
 toString ()
 
Returns
string Debugging string describing the job
Stable to override More...
 
 workItemCount ()
 Stable to override. More...
 
- Public Member Functions inherited from RunnableJob
 run ()
 Run the job. More...
 
 tearDown ( $status)
 Do any final cleanup after run(), deferred updates, and all DB commits happen. More...
 

Static Public Member Functions

static factory ( $command, $params=[])
 Create the appropriate object to handle a specific job. More...
 
static newRootJobParams ( $key)
 Get "root job" parameters for a task. More...
 

Public Attributes

string $command
 
array $metadata = []
 Additional queue metadata. More...
 
array $params
 Array of job parameters. More...
 

Protected Member Functions

 addTeardownCallback ( $callback)
 
 setLastError ( $error)
 

Protected Attributes

string $error
 Text for error that occurred last. More...
 
int $executionFlags = 0
 Bitfield of JOB_* class constants. More...
 
bool $removeDuplicates = false
 Expensive jobs may set this to true. More...
 
callable[] $teardownCallbacks = []
 
Title $title
 

Detailed Description

Class to both describe a background job and handle jobs.

To push jobs onto queues, use JobQueueGroup::singleton()->push();

Job objects are constructed by the job queue, and must have an approriate constructor signature; see IJobSpecification.

Stable to extend

Definition at line 35 of file Job.php.

Constructor & Destructor Documentation

◆ __construct()

Job::__construct (   $command,
  $params = null 
)

Stable to call.

Parameters
string$command
array | Title | null$params

Definition at line 123 of file Job.php.

References $command, $params, $title, Title\getDBkey(), Title\getNamespace(), WebRequest\getRequestId(), Title\makeTitle(), and NS_SPECIAL.

Member Function Documentation

◆ addTeardownCallback()

Job::addTeardownCallback (   $callback)
protected
Parameters
callable$callbackA function with one parameter, the success status, which will be false if the job failed or it succeeded but the DB changes could not be committed or any deferred updates threw an exception. (This parameter was added in 1.28.)
Since
1.27

Definition at line 390 of file Job.php.

Referenced by AssembleUploadChunksJob\run(), and PublishStashedFileJob\run().

◆ allowRetries()

Job::allowRetries ( )

Returns
bool Whether this job can be retried on failure by job runners
Since
1.21
Stable to override

Implements RunnableJob.

Reimplemented in ThumbnailRenderJob, PublishStashedFileJob, and AssembleUploadChunksJob.

Definition at line 282 of file Job.php.

◆ factory()

static Job::factory (   $command,
  $params = [] 
)
static

Create the appropriate object to handle a specific job.

Parameters
string$commandJob command
array | Title$paramsJob parameters
Exceptions
InvalidArgumentException
Returns
Job

Definition at line 68 of file Job.php.

References $command, $job, $params, $title, $wgJobClasses, Title\makeTitle(), and NS_SPECIAL.

Referenced by JobQueue\factoryJob().

◆ getDeduplicationInfo()

Job::getDeduplicationInfo ( )

Subclasses may need to override this to make duplication detection work.

The resulting map conveys everything that makes the job unique. This is only checked if ignoreDuplicates() returns true, meaning that duplicate jobs are supposed to be ignored.

Stable to override

Returns
array Map of key/values
Since
1.21

Implements IJobSpecification.

Reimplemented in RefreshLinksJob, PublishStashedFileJob, HTMLCacheUpdateJob, ClearUserWatchlistJob, CategoryMembershipChangeJob, and AssembleUploadChunksJob.

Definition at line 304 of file Job.php.

References getParams(), and getType().

◆ getLastError()

Job::getLastError ( )

Returns
string
Stable to override

Implements RunnableJob.

Definition at line 472 of file Job.php.

References $error.

◆ getMetadata()

Job::getMetadata (   $field = null)

Stable to override.

Parameters
string | null$fieldMetadata field or null to get all the metadata
Returns
mixed|null Value; null if missing
Since
1.33

Implements RunnableJob.

Definition at line 198 of file Job.php.

References $metadata.

Referenced by setMetadata().

◆ getParams()

Job::getParams ( )

Returns
array Parameters that specify sources, targets, and options for execution
Stable to override

Implements IJobSpecification.

Definition at line 188 of file Job.php.

References $params.

Referenced by getDeduplicationInfo(), and ClearUserWatchlistJob\run().

◆ getQueuedTimestamp()

Job::getQueuedTimestamp ( )
Returns
int|null UNIX timestamp of when the job was queued, or null
Since
1.26

Definition at line 239 of file Job.php.

References wfTimestampOrNull().

Referenced by getReadyTimestamp().

◆ getReadyTimestamp()

Job::getReadyTimestamp ( )

Returns
int|null UNIX timestamp of when the job was runnable, or null
Since
1.26
Stable to override

Implements RunnableJob.

Definition at line 257 of file Job.php.

References getQueuedTimestamp(), and getReleaseTimestamp().

◆ getReleaseTimestamp()

Job::getReleaseTimestamp ( )

Stable to override.

Returns
int|null UNIX timestamp to delay running this job until, otherwise null
Since
1.22

Implements IJobSpecification.

Definition at line 229 of file Job.php.

References wfTimestampOrNull().

Referenced by getReadyTimestamp().

◆ getRequestId()

Job::getRequestId ( )

Returns
string|null Id of the request that created this job. Follows jobs recursively, allowing to track the id of the request that started a job when jobs insert jobs which insert other jobs.
Since
1.27
Stable to override

Implements RunnableJob.

Definition at line 249 of file Job.php.

Referenced by DeletePageJob\run().

◆ getRootJobParams()

Job::getRootJobParams ( )

Stable to override.

See also
JobQueue::deduplicateRootJob()
Returns
array
Since
1.21

Implements IJobSpecification.

Definition at line 357 of file Job.php.

Referenced by HTMLCacheUpdateJob\run(), and RefreshLinksJob\run().

◆ getTitle()

Job::getTitle ( )
final
Returns
Title

Definition at line 180 of file Job.php.

References $title.

◆ getType()

Job::getType ( )

Returns
string Job type that defines what sort of changes this job makes
Stable to override

Implements IJobSpecification.

Definition at line 173 of file Job.php.

References $command.

Referenced by getDeduplicationInfo().

◆ hasExecutionFlag()

Job::hasExecutionFlag (   $flag)

Parameters
int$flagJOB_* class constant
Returns
bool
Since
1.31
Stable to override

Implements RunnableJob.

Definition at line 165 of file Job.php.

◆ hasRootJobParams()

Job::hasRootJobParams ( )

Stable to override.

See also
JobQueue::deduplicateRootJob()
Returns
bool
Since
1.22

Implements IJobSpecification.

Definition at line 370 of file Job.php.

Referenced by isRootJob().

◆ ignoreDuplicates()

Job::ignoreDuplicates ( )

Whether the queue should reject insertion of this job if a duplicate exists.

This can be used to avoid duplicated effort or combined with delayed jobs to coalesce updates into larger batches. Claimed jobs are never treated as duplicates of new jobs, and some queues may allow a few duplicates due to network partitions and fail-over. Thus, additional locking is needed to enforce mutual exclusion if this is really needed.

Stable to override

Returns
bool

Implements IJobSpecification.

Definition at line 274 of file Job.php.

References $removeDuplicates.

◆ isRootJob()

Job::isRootJob ( )

Stable to override.

See also
JobQueue::deduplicateRootJob()
Returns
bool Whether this is job is a root job

Implements IJobSpecification.

Definition at line 380 of file Job.php.

References hasRootJobParams().

◆ newRootJobParams()

static Job::newRootJobParams (   $key)
static

Get "root job" parameters for a task.

This is used to no-op redundant jobs, including child jobs of jobs, as long as the children inherit the root job parameters. When a job with root job parameters and "rootJobIsSelf" set is pushed, the deduplicateRootJob() method is automatically called on it. If the root job is only virtual and not actually pushed (e.g. the sub-jobs are inserted directly), then call deduplicateRootJob() directly.

See also
JobQueue::deduplicateRootJob()
Parameters
string$keyA key that identifies the task
Returns
array Map of:
  • rootJobIsSelf : true
  • rootJobSignature : hash (e.g. SHA1) that identifies the task
  • rootJobTimestamp : TS_MW timestamp of this instance of the task
Since
1.21

Definition at line 343 of file Job.php.

References wfTimestampNow().

Referenced by HTMLCacheUpdateJob\newForBacklinks(), and LinksUpdate\queueRecursiveJobsForTable().

◆ setLastError()

◆ setMetadata()

Job::setMetadata (   $field,
  $value 
)

Stable to override.

Parameters
string$fieldKey name to set the value for
mixed$valueThe value to set the field for
Returns
mixed|null The prior field value; null if missing
Since
1.33

Implements RunnableJob.

Definition at line 213 of file Job.php.

References getMetadata().

◆ teardown()

Job::teardown (   $status)

Stable to override

Definition at line 398 of file Job.php.

◆ toString()

Job::toString ( )

Returns
string Debugging string describing the job
Stable to override

Implements RunnableJob.

Definition at line 408 of file Job.php.

References $command, $s, and FormatJson\encode().

◆ workItemCount()

Job::workItemCount ( )

Stable to override.

Returns
int

Implements RunnableJob.

Reimplemented in RefreshLinksJob, and HTMLCacheUpdateJob.

Definition at line 290 of file Job.php.

Member Data Documentation

◆ $command

string Job::$command

Definition at line 37 of file Job.php.

Referenced by __construct(), WatchlistExpiryJob\__construct(), factory(), getType(), and toString().

◆ $error

string Job::$error
protected

Text for error that occurred last.

Definition at line 52 of file Job.php.

Referenced by getLastError(), and setLastError().

◆ $executionFlags

int Job::$executionFlags = 0
protected

Bitfield of JOB_* class constants.

Definition at line 58 of file Job.php.

◆ $metadata

array Job::$metadata = []

Additional queue metadata.

Definition at line 43 of file Job.php.

Referenced by getMetadata().

◆ $params

◆ $removeDuplicates

bool Job::$removeDuplicates = false
protected

Expensive jobs may set this to true.

Definition at line 49 of file Job.php.

Referenced by ignoreDuplicates().

◆ $teardownCallbacks

callable [] Job::$teardownCallbacks = []
protected

Definition at line 55 of file Job.php.

◆ $title


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