73 $factory = MediaWikiServices::getInstance()->getJobFactory();
77 return $factory->newJob( ...func_get_args() );
90 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
97 throw new InvalidArgumentException(
'$params must be an array' );
102 !isset(
$params[
'namespace'] ) &&
107 $params[
'namespace'] = $page->getNamespace();
108 $params[
'title'] = $page->getDBkey();
113 'requestId' => Telemetry::getInstance()->getRequestId(),
116 if ( $this->title ===
null ) {
118 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
131 return ( $this->executionFlags & $flag ) === $flag;
139 return $this->command;
164 if ( $field ===
null ) {
165 return $this->metadata;
168 return $this->metadata[$field] ??
null;
180 if ( $value ===
null ) {
181 unset( $this->metadata[$field] );
183 $this->metadata[$field] = $value;
195 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
196 return $time ? (int)$time :
null;
205 return $time ? (int)$time :
null;
213 return $this->params[
'requestId'] ??
null;
238 return $this->removeDuplicates;
272 if ( is_array( $info[
'params'] ) ) {
274 unset( $info[
'params'][
'rootJobSignature'] );
275 unset( $info[
'params'][
'rootJobTimestamp'] );
277 unset( $info[
'params'][
'jobReleaseTimestamp'] );
279 unset( $info[
'params'][
'requestId'] );
281 ksort( $info[
'params'] );
308 'rootJobIsSelf' =>
true,
309 'rootJobSignature' => sha1( $key ),
322 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
323 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
334 return isset( $this->params[
'rootJobSignature'] )
335 && isset( $this->params[
'rootJobTimestamp'] );
344 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
354 $this->teardownCallbacks[] = $callback;
362 foreach ( $this->teardownCallbacks as $callback ) {
363 call_user_func( $callback, $status );
373 if ( $this->params ) {
374 foreach ( $this->params as $key => $value ) {
375 if ( $paramString !=
'' ) {
378 if ( is_array( $value ) ) {
380 foreach ( $value as $k => $v ) {
381 $json = FormatJson::encode( $v );
382 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
383 $filteredValue[$k] = get_debug_type( $v ) .
'(...)';
385 $filteredValue[$k] = $v;
388 if ( count( $filteredValue ) <= 10 ) {
389 $value = FormatJson::encode( $filteredValue );
391 $value =
"array(" . count( $value ) .
")";
393 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
394 $value = get_debug_type( $value );
397 $flatValue = (string)$value;
398 if ( mb_strlen( $flatValue ) > 1024 ) {
399 $flatValue =
"string(" . mb_strlen( $value ) .
")";
404 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
406 $paramString .=
"$key={$flatValue}";
411 foreach ( $this->metadata as $key => $value ) {
412 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
413 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
418 if ( is_object( $this->title ) ) {
419 $s .=
' ' . $this->title->getPrefixedDBkey();
421 if ( $paramString !=
'' ) {
422 $s .=
" $paramString";
424 if ( $metaString !=
'' ) {
425 $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()
Whether to retry execution of this job if run() returned false or threw an exception....
__construct( $command, $params=null)
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack().