MediaWiki  1.28.0
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 ()
 
 getQueuedTimestamp ()
 
 getReadyTimestamp ()
 
 getReleaseTimestamp ()
 
 getRequestId ()
 
 getRootJobParams ()
 
 getTitle ()
 
 getType ()
 
 hasRootJobParams ()
 
 ignoreDuplicates ()
 Whether the queue should reject insertion of this job if a duplicate exists. More...
 
 insert ()
 Insert a single job into the queue. More...
 
 isRootJob ()
 
 run ()
 Run the job. More...
 
 teardown ($status)
 Do any final cleanup after run(), deferred updates, and all DB commits happen. 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=[])
 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...
 
bool $removeDuplicates
 Expensive jobs may set this to true. More...
 
callable[] $teardownCallbacks = []
 
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

Job::__construct (   $command,
  $title,
  $params = false 
)
Parameters
string$command
Title$title
array | bool$paramsCan not be === true

Definition at line 88 of file Job.php.

References $command, $title, WebRequest\getRequestId(), and title.

Member Function Documentation

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 309 of file Job.php.

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

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

Definition at line 198 of file Job.php.

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
Job[]$jobs Array of Job objects
Returns
bool
Deprecated:
since 1.21

Definition at line 112 of file Job.php.

References JobQueueGroup\singleton(), and wfDeprecated().

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

Create the appropriate object to handle a specific job.

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

Definition at line 68 of file Job.php.

References $command, $job, and global.

Referenced by JobQueueDB\doPop(), JobQueueRedis\getJobFromFields(), JobQueueRedis\getJobFromUidInternal(), JobQueueDB\getJobIterator(), and JobQueueMemory\jobFromSpecInternal().

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.

Definition at line 220 of file Job.php.

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

Job::getLastError ( )

Definition at line 397 of file Job.php.

References $error.

Referenced by JobRunner\executeJob().

Job::getParams ( )
Returns
array

Implements IJobSpecification.

Definition at line 135 of file Job.php.

References $params.

Referenced by getDeduplicationInfo(), DuplicateJob\newFromJob(), and BacklinkJobUtils\partitionBacklinkJob().

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

Definition at line 153 of file Job.php.

References TS_UNIX, and wfTimestampOrNull().

Referenced by getReadyTimestamp().

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

Definition at line 175 of file Job.php.

References getQueuedTimestamp(), and getReleaseTimestamp().

Referenced by JobRunner\executeJob().

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

Implements IJobSpecification.

Definition at line 143 of file Job.php.

References TS_UNIX, and wfTimestampOrNull().

Referenced by getReadyTimestamp().

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

Definition at line 165 of file Job.php.

Job::getTitle ( )
Returns
Title

Implements IJobSpecification.

Definition at line 128 of file Job.php.

References $title.

Referenced by getDeduplicationInfo(), DuplicateJob\newFromJob(), and BacklinkJobUtils\partitionBacklinkJob().

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

Implements IJobSpecification.

Definition at line 290 of file Job.php.

Referenced by JobQueueRedis\doIsRootJobOldDuplicate(), JobQueue\doIsRootJobOldDuplicate(), and isRootJob().

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.

Returns
bool

Implements IJobSpecification.

Definition at line 190 of file Job.php.

References $removeDuplicates.

Job::insert ( )

Insert a single job into the queue.

Returns
bool True on success
Deprecated:
since 1.21

Definition at line 329 of file Job.php.

References JobQueueGroup\singleton().

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

Implements IJobSpecification.

Definition at line 299 of file Job.php.

References hasRootJobParams().

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 261 of file Job.php.

References wfTimestampNow().

Referenced by HTMLCacheUpdateJob\newForBacklinks(), LinksUpdate\queueRecursiveJobsForTable(), RefreshLinksPartitionTest\testRefreshLinks(), and JobQueueTest\testRootDeduplication().

Job::run ( )
abstract

Run the job.

Returns
bool Success

Referenced by JobRunner\executeJob().

Job::teardown (   $status)

Do any final cleanup after run(), deferred updates, and all DB commits happen.

Parameters
bool$statusWhether the job, its deferred updates, and DB commit all succeeded
Since
1.27

Definition at line 318 of file Job.php.

References $status, and as.

Referenced by JobRunner\executeJob().

Job::toString ( )
Returns
string

Definition at line 337 of file Job.php.

References $command, $s, $value, as, FormatJson\encode(), string, and title.

Referenced by JobRunner\commitMasterChanges(), and JobRunner\executeJob().

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

Definition at line 207 of file Job.php.

Referenced by JobRunner\getBackoffTimeToWait().

Member Data Documentation

string Job::$command

Definition at line 33 of file Job.php.

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

string Job::$error
protected

Text for error that occurred last.

Definition at line 48 of file Job.php.

Referenced by getLastError(), and setLastError().

array Job::$metadata = []

Additional queue metadata.

Definition at line 39 of file Job.php.

array Job::$params

Array of job parameters.

Definition at line 36 of file Job.php.

Referenced by getParams(), RefreshLinksJob\newDynamic(), RefreshLinksJob\newPrioritized(), NullJob\run(), and RefreshLinksJob\run().

bool Job::$removeDuplicates
protected

Expensive jobs may set this to true.

Definition at line 45 of file Job.php.

Referenced by ignoreDuplicates().

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

Definition at line 51 of file Job.php.


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