MediaWiki master
MediaWiki\JobQueue\Job Class Reference

Describe and execute a background job. More...

Inherits MediaWiki\JobQueue\RunnableJob.

Inherited by EmaillingJob, EnotifNotifyJob, MediaWiki\JobQueue\Jobs\AssembleUploadChunksJob, MediaWiki\JobQueue\Jobs\CategoryMembershipChangeJob, MediaWiki\JobQueue\Jobs\CdnPurgeJob, MediaWiki\JobQueue\Jobs\DeleteLinksJob, MediaWiki\JobQueue\Jobs\DeletePageJob, MediaWiki\JobQueue\Jobs\DoubleRedirectJob, MediaWiki\JobQueue\Jobs\DuplicateJob, MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob, MediaWiki\JobQueue\Jobs\NullJob, MediaWiki\JobQueue\Jobs\ParsoidCachePrewarmJob, MediaWiki\JobQueue\Jobs\PublishStashedFileJob, MediaWiki\JobQueue\Jobs\RefreshLinksJob, MediaWiki\JobQueue\Jobs\RevertedTagUpdateJob, MediaWiki\JobQueue\Jobs\ThumbnailRenderJob, MediaWiki\JobQueue\Jobs\UploadFromUrlJob, MediaWiki\RecentChanges\RecentChangesUpdateJob, MediaWiki\RenameUser\Job\RenameUserDerivedJob, MediaWiki\RenameUser\Job\RenameUserTableJob, MediaWiki\Watchlist\ActivityUpdateJob, MediaWiki\Watchlist\ClearUserWatchlistJob, MediaWiki\Watchlist\ClearWatchlistNotificationsJob, MediaWiki\Watchlist\WatchlistExpiryJob, UserEditCountInitJob, UserGroupExpiryJob, and UserOptionsUpdateJob.

Collaboration diagram for MediaWiki\JobQueue\Job:

Public Member Functions

 __construct ( $command, $params=null)
 
 allowRetries ()
 Whether to retry execution of this job if run() returned false or threw an exception.
Warning
In some setups (i.e. when using change-propagation) jobs may still be retried even when this is false if the job fails due to a timeout unless it is also configured in change-prop config (T358939).
Returns
bool Whether this job can be retried on failure by job runners
Since
1.21

 
 getDeduplicationInfo ()
 Subclasses may need to override this to make duplication detection work.
 
 getLastError ()
 
Returns
string

 
 getMetadata ( $field=null)
 
 getParams ()
 
Returns
array Parameters that specify sources, targets, and options for execution

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

 
 getReleaseTimestamp ()
 
 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

 
 getRootJobParams ()
 
 getTitle ()
 
 getType ()
 
Returns
string Job type that defines what sort of changes this job makes

 
 hasExecutionFlag ( $flag)
 
Parameters
int$flagJOB_* class constant
Returns
bool
Since
1.31

 
 hasRootJobParams ()
 
 ignoreDuplicates ()
 Whether the queue should reject insertion of this job if a duplicate exists.
 
 isRootJob ()
 
 setMetadata ( $field, $value)
 
 teardown ( $status)
 
 toString ()
 
Returns
string Debugging string describing the job

 
 workItemCount ()
 
- Public Member Functions inherited from MediaWiki\JobQueue\RunnableJob
 run ()
 Run the job.
 
 tearDown ( $status)
 Do any final cleanup after run(), deferred updates, and all DB commits happen.
 

Static Public Member Functions

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

Public Attributes

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

Protected Member Functions

 addTeardownCallback ( $callback)
 
 setLastError ( $error)
 

Protected Attributes

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

Detailed Description

Describe and execute a background job.

Callers should use JobQueueGroup to enqueue jobs for deferred execution.

See the architecture doc for more information.

Stability: stable
to extend
Since
1.6

Definition at line 41 of file Job.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\JobQueue\Job::__construct ( $command,
$params = null )
Stability: stable
to call
Parameters
string$command
array | PageReference | null$paramsThe parameters for the job. Note that if providing, a 'requestId' key it should be a value from Telemetry::getRequestId.

Definition at line 90 of file Job.php.

References MediaWiki\JobQueue\Job\$command, MediaWiki\JobQueue\Job\$params, and NS_SPECIAL.

Member Function Documentation

◆ addTeardownCallback()

MediaWiki\JobQueue\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 357 of file Job.php.

Referenced by MediaWiki\JobQueue\Jobs\AssembleUploadChunksJob\run().

◆ allowRetries()

MediaWiki\JobQueue\Job::allowRetries ( )

Whether to retry execution of this job if run() returned false or threw an exception.

Warning
In some setups (i.e. when using change-propagation) jobs may still be retried even when this is false if the job fails due to a timeout unless it is also configured in change-prop config (T358939).
Returns
bool Whether this job can be retried on failure by job runners
Since
1.21

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Reimplemented in MediaWiki\JobQueue\Jobs\AssembleUploadChunksJob, and MediaWiki\JobQueue\Jobs\ThumbnailRenderJob.

Definition at line 249 of file Job.php.

◆ factory()

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

Create the appropriate object to handle a specific job.

Deprecated
since 1.40, use JobFactory instead.
Parameters
string$commandJob command
array | PageReference$paramsJob parameters
Returns
Job

Definition at line 75 of file Job.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ getDeduplicationInfo()

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

Stability: stable
to override
Returns
array Map of key/values
Since
1.21

Implements MediaWiki\JobQueue\IJobSpecification.

Reimplemented in MediaWiki\JobQueue\Jobs\AssembleUploadChunksJob, MediaWiki\JobQueue\Jobs\CategoryMembershipChangeJob, MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob, MediaWiki\JobQueue\Jobs\PublishStashedFileJob, MediaWiki\JobQueue\Jobs\RefreshLinksJob, MediaWiki\JobQueue\Jobs\UploadFromUrlJob, and MediaWiki\Watchlist\ClearUserWatchlistJob.

Definition at line 271 of file Job.php.

References MediaWiki\JobQueue\Job\getParams(), and MediaWiki\JobQueue\Job\getType().

◆ getLastError()

MediaWiki\JobQueue\Job::getLastError ( )

Returns
string

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Definition at line 443 of file Job.php.

References MediaWiki\JobQueue\Job\$error.

◆ getMetadata()

MediaWiki\JobQueue\Job::getMetadata ( $field = null)
Stability: 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 MediaWiki\JobQueue\RunnableJob.

Definition at line 167 of file Job.php.

References MediaWiki\JobQueue\Job\$metadata.

Referenced by MediaWiki\JobQueue\Job\setMetadata().

◆ getParams()

MediaWiki\JobQueue\Job::getParams ( )

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

Stability: stable
to override

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 157 of file Job.php.

References MediaWiki\JobQueue\Job\$params.

Referenced by MediaWiki\JobQueue\Job\getDeduplicationInfo(), and MediaWiki\Watchlist\ClearUserWatchlistJob\run().

◆ getQueuedTimestamp()

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

Definition at line 207 of file Job.php.

References wfTimestampOrNull().

Referenced by MediaWiki\JobQueue\Job\getReadyTimestamp().

◆ getReadyTimestamp()

MediaWiki\JobQueue\Job::getReadyTimestamp ( )

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

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Definition at line 224 of file Job.php.

References MediaWiki\JobQueue\Job\getQueuedTimestamp(), and MediaWiki\JobQueue\Job\getReleaseTimestamp().

◆ getReleaseTimestamp()

MediaWiki\JobQueue\Job::getReleaseTimestamp ( )
Stability: stable
to override
Returns
int|null UNIX timestamp to delay running this job until, otherwise null
Since
1.22

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 198 of file Job.php.

References wfTimestampOrNull().

Referenced by MediaWiki\JobQueue\Job\getReadyTimestamp().

◆ getRequestId()

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

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Definition at line 216 of file Job.php.

Referenced by MediaWiki\JobQueue\Jobs\DeletePageJob\run().

◆ getRootJobParams()

MediaWiki\JobQueue\Job::getRootJobParams ( )
Stability: stable
to override
See also
JobQueue::deduplicateRootJob()
Returns
array
Since
1.21

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 324 of file Job.php.

Referenced by MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob\run(), and MediaWiki\JobQueue\Jobs\RefreshLinksJob\run().

◆ getTitle()

MediaWiki\JobQueue\Job::getTitle ( )
final
Returns
Title

Definition at line 149 of file Job.php.

References MediaWiki\JobQueue\Job\$title.

◆ getType()

MediaWiki\JobQueue\Job::getType ( )

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

Stability: stable
to override

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 142 of file Job.php.

References MediaWiki\JobQueue\Job\$command.

Referenced by MediaWiki\JobQueue\Job\getDeduplicationInfo().

◆ hasExecutionFlag()

MediaWiki\JobQueue\Job::hasExecutionFlag ( $flag)

Parameters
int$flagJOB_* class constant
Returns
bool
Since
1.31

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Definition at line 134 of file Job.php.

◆ hasRootJobParams()

MediaWiki\JobQueue\Job::hasRootJobParams ( )
Stability: stable
to override
See also
JobQueue::deduplicateRootJob()
Returns
bool
Since
1.22

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 337 of file Job.php.

Referenced by MediaWiki\JobQueue\Job\isRootJob().

◆ ignoreDuplicates()

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

Stability: stable
to override
Returns
bool

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 241 of file Job.php.

References MediaWiki\JobQueue\Job\$removeDuplicates.

◆ isRootJob()

MediaWiki\JobQueue\Job::isRootJob ( )
Stability: stable
to override
See also
JobQueue::deduplicateRootJob()
Returns
bool Whether this is job is a root job

Implements MediaWiki\JobQueue\IJobSpecification.

Definition at line 347 of file Job.php.

References MediaWiki\JobQueue\Job\hasRootJobParams().

◆ newRootJobParams()

static MediaWiki\JobQueue\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 310 of file Job.php.

References wfTimestampNow().

Referenced by MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob\newForBacklinks(), and MediaWiki\Deferred\LinksUpdate\LinksUpdate\queueRecursiveJobsForTable().

◆ setLastError()

◆ setMetadata()

MediaWiki\JobQueue\Job::setMetadata ( $field,
$value )
Stability: 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 MediaWiki\JobQueue\RunnableJob.

Definition at line 182 of file Job.php.

References MediaWiki\JobQueue\Job\getMetadata().

◆ teardown()

MediaWiki\JobQueue\Job::teardown ( $status)

Stability: stable
to override

Definition at line 365 of file Job.php.

◆ toString()

MediaWiki\JobQueue\Job::toString ( )

Returns
string Debugging string describing the job

Stability: stable
to override

Implements MediaWiki\JobQueue\RunnableJob.

Definition at line 375 of file Job.php.

References MediaWiki\JobQueue\Job\$command.

◆ workItemCount()

MediaWiki\JobQueue\Job::workItemCount ( )
Stability: stable
to override
Returns
int

Implements MediaWiki\JobQueue\RunnableJob.

Reimplemented in MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob, and MediaWiki\JobQueue\Jobs\RefreshLinksJob.

Definition at line 257 of file Job.php.

Member Data Documentation

◆ $command

◆ $error

string MediaWiki\JobQueue\Job::$error
protected

Text for error that occurred last.

Definition at line 58 of file Job.php.

Referenced by MediaWiki\JobQueue\Job\getLastError(), and MediaWiki\JobQueue\Job\setLastError().

◆ $executionFlags

int MediaWiki\JobQueue\Job::$executionFlags = 0
protected

Bitfield of JOB_* class constants.

Definition at line 64 of file Job.php.

◆ $metadata

array MediaWiki\JobQueue\Job::$metadata = []

Additional queue metadata.

Definition at line 49 of file Job.php.

Referenced by MediaWiki\JobQueue\Job\getMetadata().

◆ $params

array MediaWiki\JobQueue\Job::$params

Array of job parameters.

Definition at line 46 of file Job.php.

Referenced by MediaWiki\JobQueue\Job\__construct(), MediaWiki\Watchlist\ActivityUpdateJob\__construct(), MediaWiki\JobQueue\Jobs\AssembleUploadChunksJob\__construct(), MediaWiki\JobQueue\Jobs\CdnPurgeJob\__construct(), MediaWiki\JobQueue\Jobs\DeletePageJob\__construct(), MediaWiki\JobQueue\Jobs\DuplicateJob\__construct(), MediaWiki\JobQueue\Jobs\NullJob\__construct(), MediaWiki\JobQueue\Jobs\PublishStashedFileJob\__construct(), MediaWiki\JobQueue\Jobs\UploadFromUrlJob\__construct(), MediaWiki\Watchlist\ClearUserWatchlistJob\__construct(), MediaWiki\Watchlist\ClearWatchlistNotificationsJob\__construct(), MediaWiki\JobQueue\Jobs\ParsoidCachePrewarmJob\__construct(), MediaWiki\JobQueue\Jobs\CategoryMembershipChangeJob\__construct(), MediaWiki\JobQueue\Jobs\RefreshLinksJob\__construct(), MediaWiki\JobQueue\Jobs\DoubleRedirectJob\__construct(), MediaWiki\Watchlist\WatchlistExpiryJob\__construct(), MediaWiki\RenameUser\Job\RenameUserTableJob\__construct(), MediaWiki\RenameUser\Job\RenameUserDerivedJob\__construct(), MediaWiki\JobQueue\Jobs\DeleteLinksJob\__construct(), MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob\__construct(), MediaWiki\JobQueue\Jobs\ThumbnailRenderJob\__construct(), MediaWiki\RecentChanges\RecentChangesUpdateJob\__construct(), MediaWiki\JobQueue\Job\getParams(), MediaWiki\JobQueue\Jobs\RefreshLinksJob\newDynamic(), MediaWiki\JobQueue\Jobs\HTMLCacheUpdateJob\newForBacklinks(), MediaWiki\JobQueue\Jobs\RefreshLinksJob\newPrioritized(), and MediaWiki\JobQueue\Jobs\NullJob\run().

◆ $removeDuplicates

bool MediaWiki\JobQueue\Job::$removeDuplicates = false
protected

Expensive jobs may set this to true.

Definition at line 55 of file Job.php.

Referenced by MediaWiki\JobQueue\Job\ignoreDuplicates().

◆ $teardownCallbacks

callable [] MediaWiki\JobQueue\Job::$teardownCallbacks = []
protected

Definition at line 61 of file Job.php.

◆ $title


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