77 $factory = MediaWikiServices::getInstance()->getJobFactory();
81 return $factory->newJob( ...func_get_args() );
94 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
101 throw new InvalidArgumentException(
'$params must be an array' );
106 !isset(
$params[
'namespace'] ) &&
111 $params[
'namespace'] = $page->getNamespace();
112 $params[
'title'] = $page->getDBkey();
117 'requestId' => Telemetry::getInstance()->getRequestId(),
120 if ( $this->title ===
null ) {
122 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
135 return ( $this->executionFlags & $flag ) === $flag;
143 return $this->command;
168 if ( $field ===
null ) {
169 return $this->metadata;
172 return $this->metadata[$field] ??
null;
184 if ( $value ===
null ) {
185 unset( $this->metadata[$field] );
187 $this->metadata[$field] = $value;
199 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
200 return $time ? (int)$time :
null;
209 return $time ? (int)$time :
null;
217 return $this->params[
'requestId'] ??
null;
242 return $this->removeDuplicates;
276 if ( is_array( $info[
'params'] ) ) {
278 unset( $info[
'params'][
'rootJobSignature'] );
279 unset( $info[
'params'][
'rootJobTimestamp'] );
281 unset( $info[
'params'][
'jobReleaseTimestamp'] );
283 unset( $info[
'params'][
'requestId'] );
285 ksort( $info[
'params'] );
312 'rootJobIsSelf' =>
true,
313 'rootJobSignature' => sha1( $key ),
326 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
327 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
338 return isset( $this->params[
'rootJobSignature'] )
339 && isset( $this->params[
'rootJobTimestamp'] );
348 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
358 $this->teardownCallbacks[] = $callback;
366 foreach ( $this->teardownCallbacks as $callback ) {
367 call_user_func( $callback, $status );
377 if ( $this->params ) {
378 foreach ( $this->params as $key => $value ) {
379 if ( $paramString !=
'' ) {
382 if ( is_array( $value ) ) {
384 foreach ( $value as $k => $v ) {
385 $json = FormatJson::encode( $v );
386 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
387 $filteredValue[$k] = get_debug_type( $v ) .
'(...)';
389 $filteredValue[$k] = $v;
392 if ( count( $filteredValue ) <= 10 ) {
393 $value = FormatJson::encode( $filteredValue );
395 $value =
"array(" . count( $value ) .
")";
397 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
398 $value = get_debug_type( $value );
401 $flatValue = (string)$value;
402 if ( mb_strlen( $flatValue ) > 1024 ) {
403 $flatValue =
"string(" . mb_strlen( $value ) .
")";
408 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
410 $paramString .=
"$key={$flatValue}";
415 foreach ( $this->metadata as $key => $value ) {
416 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
417 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
422 if ( is_object( $this->title ) ) {
423 $s .=
' ' . $this->title->getPrefixedDBkey();
425 if ( $paramString !=
'' ) {
426 $s .=
" $paramString";
428 if ( $metaString !=
'' ) {
429 $s .=
" ($metaString)";
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.
array $params
The job parameters.
Describe and execute a background job.
setMetadata( $field, $value)
getParams()
array Parameters that specify sources, targets, and options for execution
getReadyTimestamp()
int|null UNIX timestamp of when the job was runnable, or null 1.26
toString()
string Debugging string describing the job
getType()
string Job type that defines what sort of changes this job makes
hasExecutionFlag( $flag)
bool 1.31
callable[] $teardownCallbacks
bool $removeDuplicates
Expensive jobs may set this to true.
getMetadata( $field=null)
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.
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.
ignoreDuplicates()
Whether the queue should reject insertion of this job if a duplicate exists.
string $error
Text for error that occurred last.
allowRetries()
In some setups (i.e. when using change-propagation) jobs may still be retried even when this is false...
__construct( $command, $params=null)
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack().