MediaWiki  1.23.6
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, $title, $params=false)
 
 allowRetries ()
 
 getDeduplicationInfo ()
 Subclasses may need to override this to make duplication detection work. More...
 
 getLastError ()
 
 getParams ()
 
 getReleaseTimestamp ()
 
 getRootJobParams ()
 
 getTitle ()
 
 getType ()
 
 hasRootJobParams ()
 
 ignoreDuplicates ()
 
 insert ()
 Insert a single job into the queue. More...
 
 run ()
 Run the job. More...
 
 toString ()
 
 workItemCount ()
 

Static Public Member Functions

static batchInsert ( $jobs)
 Batch-insert a group of jobs into the queue. More...
 
static factory ( $command, Title $title, $params=false)
 Create the appropriate object to handle a specific job. More...
 
static newRootJobParams ( $key)
 
static pop ()
 Pop a job off the front of the queue. More...
 
static pop_type ( $type)
 Pop a job of a certain type. More...
 
static safeBatchInsert ( $jobs)
 Insert a group of jobs into the queue. More...
 

Public Attributes

string $command
 
array $metadata = array()
 Additional queue metadata *. More...
 
array bool $params
 Array of job parameters or false if none *. More...
 

Protected Member Functions

 setLastError ( $error)
 

Protected Attributes

string $error
 Text for error that occurred last *. More...
 
bool $removeDuplicates
 Expensive jobs may set this to true *. More...
 
Title $title
 

Detailed Description

Class to both describe a background job and handle jobs.

The queue aspects of this class are now deprecated. Using the class to push jobs onto queues is deprecated (use JobSpecification).

Definition at line 31 of file Job.php.

Constructor & Destructor Documentation

◆ __construct()

Job::__construct (   $command,
  $title,
  $params = false 
)
Parameters
$command
$title
$paramsarray|bool

Definition at line 140 of file Job.php.

References $command, $params, $title, and title.

Member Function Documentation

◆ allowRetries()

Job::allowRetries ( )
Returns
bool Whether this job can be retried on failure by job runners
Since
1.21

Reimplemented in PublishStashedFileJob, and AssembleUploadChunksJob.

Definition at line 191 of file Job.php.

◆ batchInsert()

static Job::batchInsert (   $jobs)
static

Batch-insert a group of jobs into the queue.

This will be wrapped in a transaction with a forced commit.

This may add duplicate at insert time, but they will be removed later on, when the first one is popped.

Parameters
array$jobsof Job objects
Returns
bool
Deprecated:
since 1.21

Definition at line 88 of file Job.php.

References JobQueueGroup\singleton().

◆ factory()

static Job::factory (   $command,
Title  $title,
  $params = false 
)
static

Create the appropriate object to handle a specific job.

Parameters
string$commandJob command
Title$titleAssociated title
array | bool$paramsJob parameters
Exceptions
MWException
Returns
Job

Definition at line 67 of file Job.php.

References $command, $params, $title, and global.

Referenced by JobQueueDB\doPop(), JobQueueDB\getAllQueuedJobs(), JobQueueRedis\getJobFromFields(), and JobQueueRedis\getJobFromUidInternal().

◆ 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.

Returns
array Map of key/values
Since
1.21

Implements IJobSpecification.

Reimplemented in RefreshLinksJob, PublishStashedFileJob, RefreshLinksJob2, and AssembleUploadChunksJob.

Definition at line 213 of file Job.php.

References array(), getParams(), getTitle(), and getType().

◆ getLastError()

Job::getLastError ( )

Definition at line 321 of file Job.php.

References $error.

◆ getParams()

Job::getParams ( )
Returns
array

Implements IJobSpecification.

Definition at line 166 of file Job.php.

References $params.

Referenced by getDeduplicationInfo().

◆ getReleaseTimestamp()

Job::getReleaseTimestamp ( )
Returns
int|null UNIX timestamp to delay running this job until, otherwise null
Since
1.22

Implements IJobSpecification.

Definition at line 174 of file Job.php.

References TS_UNIX, and wfTimestampOrNull().

◆ getRootJobParams()

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

Definition at line 251 of file Job.php.

References array().

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

◆ getTitle()

Job::getTitle ( )
Returns
Title

Implements IJobSpecification.

Definition at line 159 of file Job.php.

References $title.

Referenced by getDeduplicationInfo().

◆ getType()

Job::getType ( )
Returns
string

Implements IJobSpecification.

Definition at line 152 of file Job.php.

References $command.

Referenced by JobQueueGroup\ack(), JobQueueGroup\deduplicateRootJob(), and getDeduplicationInfo().

◆ hasRootJobParams()

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

Definition at line 267 of file Job.php.

◆ ignoreDuplicates()

Job::ignoreDuplicates ( )
Returns
bool Whether only one of each identical set of jobs should be run

Implements IJobSpecification.

Definition at line 183 of file Job.php.

References $removeDuplicates.

◆ insert()

Job::insert ( )

Insert a single job into the queue.

Returns
bool true on success
Deprecated:
since 1.21

Definition at line 277 of file Job.php.

References JobQueueGroup\singleton().

◆ newRootJobParams()

static Job::newRootJobParams (   $key)
static
See also
JobQueue::deduplicateRootJob()
Parameters
string$keyA key that identifies the task
Returns
array Map of:
  • 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 239 of file Job.php.

References array(), and wfTimestampNow().

Referenced by HTMLCacheUpdate\doUpdate(), LinksUpdate\queueRecursiveJobsForTable(), RefreshLinksPartitionTest\testRefreshLinks(), and JobQueueTest\testRootDeduplication().

◆ pop()

static Job::pop ( )
static

Pop a job off the front of the queue.

This is subject to $wgJobTypesExcludedFromDefaultQueue.

Returns
Job|bool False if there are no jobs
Deprecated:
since 1.21

Definition at line 127 of file Job.php.

References JobQueueGroup\singleton().

◆ pop_type()

static Job::pop_type (   $type)
static

Pop a job of a certain type.

This tries less hard than pop() to actually find a job; it may be adversely affected by concurrent job runners.

Parameters
$typestring
Returns
Job|bool Returns false if there are no jobs
Deprecated:
since 1.21

Definition at line 116 of file Job.php.

References $type, and JobQueueGroup\singleton().

◆ run()

◆ safeBatchInsert()

static Job::safeBatchInsert (   $jobs)
static

Insert a group of jobs into the queue.

Same as batchInsert() but does not commit and can thus be rolled-back as part of a larger transaction. However, large batches of jobs can cause slave lag.

Parameters
array$jobsof Job objects
Returns
bool
Deprecated:
since 1.21

Definition at line 103 of file Job.php.

References JobQueue\QOS_ATOMIC, and JobQueueGroup\singleton().

◆ setLastError()

Job::setLastError (   $error)
protected

◆ toString()

Job::toString ( )
Returns
string

Definition at line 284 of file Job.php.

References $s, $value, as, and title.

◆ workItemCount()

Job::workItemCount ( )
Returns
integer Number of actually "work items" handled in this job
See also
$wgJobBackoffThrottling
Since
1.23

Reimplemented in RefreshLinksJob, and HTMLCacheUpdateJob.

Definition at line 200 of file Job.php.

Member Data Documentation

◆ $command

string Job::$command

Definition at line 32 of file Job.php.

Referenced by __construct(), factory(), and getType().

◆ $error

string Job::$error
protected

Text for error that occurred last *.

Definition at line 42 of file Job.php.

Referenced by getLastError(), and setLastError().

◆ $metadata

array Job::$metadata = array()

Additional queue metadata *.

Definition at line 36 of file Job.php.

◆ $params

◆ $removeDuplicates

bool Job::$removeDuplicates
protected

Expensive jobs may set this to true *.

Definition at line 40 of file Job.php.

Referenced by ignoreDuplicates().

◆ $title


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