71 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
72 } elseif ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) ) {
88 if ( is_callable( $handler ) ) {
90 } elseif ( class_exists( $handler ) ) {
91 if ( is_subclass_of( $handler, GenericParameterJob::class ) ) {
105 throw new InvalidArgumentException(
106 "Could not instantiate job '$command': bad spec!"
111 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
124 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
131 throw new InvalidArgumentException(
'$params must be an array' );
136 !isset(
$params[
'namespace'] ) &&
146 $this->params =
$params + [
'requestId' => WebRequest::getRequestId() ];
148 if ( $this->title ===
null ) {
150 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
163 return ( $this->executionFlags & $flag ) === $flag;
196 if ( $field ===
null ) {
200 return $this->metadata[$field] ??
null;
212 if ( $value ===
null ) {
213 unset( $this->metadata[$field] );
215 $this->metadata[$field] = $value;
227 return isset( $this->params[
'jobReleaseTimestamp'] )
237 return isset( $this->metadata[
'timestamp'] )
247 return $this->params[
'requestId'] ??
null;
306 if ( is_array( $info[
'params'] ) ) {
308 unset( $info[
'params'][
'rootJobSignature'] );
309 unset( $info[
'params'][
'rootJobTimestamp'] );
311 unset( $info[
'params'][
'jobReleaseTimestamp'] );
313 unset( $info[
'params'][
'requestId'] );
315 ksort( $info[
'params'] );
342 'rootJobIsSelf' =>
true,
343 'rootJobSignature' => sha1( $key ),
356 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
357 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
368 return isset( $this->params[
'rootJobSignature'] )
369 && isset( $this->params[
'rootJobTimestamp'] );
378 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
388 $this->teardownCallbacks[] = $callback;
396 foreach ( $this->teardownCallbacks as $callback ) {
397 call_user_func( $callback, $status );
407 if ( $this->params ) {
408 foreach ( $this->params as $key => $value ) {
409 if ( $paramString !=
'' ) {
412 if ( is_array( $value ) ) {
414 foreach ( $value as $k => $v ) {
415 $json = FormatJson::encode( $v );
416 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
417 $filteredValue[$k] = gettype( $v ) .
'(...)';
419 $filteredValue[$k] = $v;
422 if ( count( $filteredValue ) <= 10 ) {
423 $value = FormatJson::encode( $filteredValue );
425 $value =
"array(" . count( $value ) .
")";
427 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
428 $value =
"object(" . get_class( $value ) .
")";
431 $flatValue = (string)$value;
432 if ( mb_strlen( $flatValue ) > 1024 ) {
433 $flatValue =
"string(" . mb_strlen( $value ) .
")";
436 $paramString .=
"$key={$flatValue}";
441 foreach ( $this->metadata as $key => $value ) {
442 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
443 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
448 if ( is_object( $this->title ) ) {
449 $s .=
" {$this->title->getPrefixedDBkey()}";
451 if ( $paramString !=
'' ) {
452 $s .=
" $paramString";
454 if ( $metaString !=
'' ) {
455 $s .=
" ($metaString)";
$wgJobClasses
Maps jobs to their handlers; extensions can add to this to provide custom jobs.
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Class to both describe a background job and handle jobs.
hasRootJobParams()
Stable to override.
setMetadata( $field, $value)
Stable to override.
getParams()
array Parameters that specify sources, targets, and options for execution Stable to override
getReadyTimestamp()
int|null UNIX timestamp of when the job was runnable, or null 1.26 Stable to override
toString()
string Debugging string describing the job Stable to override
getType()
string Job type that defines what sort of changes this job makes Stable to override
getRootJobParams()
Stable to override.
hasExecutionFlag( $flag)
bool 1.31 Stable to override
callable[] $teardownCallbacks
bool $removeDuplicates
Expensive jobs may set this to true.
getMetadata( $field=null)
Stable to override.
teardown( $status)
Stable to override
isRootJob()
Stable to override.
addTeardownCallback( $callback)
array $params
Array of job parameters.
array $metadata
Additional queue metadata.
static factory( $command, $params=[])
Create the appropriate object to handle a specific job.
int $executionFlags
Bitfield of JOB_* class constants.
workItemCount()
Stable to override.
getRequestId()
string|null Id of the request that created this job. Follows jobs recursively, allowing to track the ...
static newRootJobParams( $key)
Get "root job" parameters for a task.
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
getReleaseTimestamp()
Stable to override.
ignoreDuplicates()
Whether the queue should reject insertion of this job if a duplicate exists.
getLastError()
string Stable to override
string $error
Text for error that occurred last.
allowRetries()
bool Whether this job can be retried on failure by job runners 1.21 Stable to override
__construct( $command, $params=null)
Stable to call.
Represents a title within MediaWiki.
getNamespace()
Get the namespace index, i.e.
getDBkey()
Get the main part with underscores.
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
if(count( $args)< 1) $job