76 $factory = MediaWikiServices::getInstance()->getJobFactory();
80 return $factory->newJob( ...func_get_args() );
93 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
100 throw new InvalidArgumentException(
'$params must be an array' );
105 !isset(
$params[
'namespace'] ) &&
110 $params[
'namespace'] = $page->getNamespace();
111 $params[
'title'] = $page->getDBkey();
116 'requestId' => Telemetry::getInstance()->getRequestId(),
119 if ( $this->title ===
null ) {
121 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
134 return ( $this->executionFlags & $flag ) === $flag;
142 return $this->command;
167 if ( $field ===
null ) {
168 return $this->metadata;
171 return $this->metadata[$field] ??
null;
183 if ( $value ===
null ) {
184 unset( $this->metadata[$field] );
186 $this->metadata[$field] = $value;
198 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
199 return $time ? (int)$time :
null;
208 return $time ? (int)$time :
null;
216 return $this->params[
'requestId'] ??
null;
241 return $this->removeDuplicates;
275 if ( is_array( $info[
'params'] ) ) {
277 unset( $info[
'params'][
'rootJobSignature'] );
278 unset( $info[
'params'][
'rootJobTimestamp'] );
280 unset( $info[
'params'][
'jobReleaseTimestamp'] );
282 unset( $info[
'params'][
'requestId'] );
284 ksort( $info[
'params'] );
311 'rootJobIsSelf' =>
true,
312 'rootJobSignature' => sha1( $key ),
325 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
326 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
337 return isset( $this->params[
'rootJobSignature'] )
338 && isset( $this->params[
'rootJobTimestamp'] );
347 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
357 $this->teardownCallbacks[] = $callback;
365 foreach ( $this->teardownCallbacks as $callback ) {
366 call_user_func( $callback, $status );
376 if ( $this->params ) {
377 foreach ( $this->params as $key => $value ) {
378 if ( $paramString !=
'' ) {
381 if ( is_array( $value ) ) {
383 foreach ( $value as $k => $v ) {
384 $json = FormatJson::encode( $v );
385 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
386 $filteredValue[$k] = gettype( $v ) .
'(...)';
388 $filteredValue[$k] = $v;
391 if ( count( $filteredValue ) <= 10 ) {
392 $value = FormatJson::encode( $filteredValue );
394 $value =
"array(" . count( $value ) .
")";
396 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
397 $value =
"object(" . get_class( $value ) .
")";
400 $flatValue = (string)$value;
401 if ( mb_strlen( $flatValue ) > 1024 ) {
402 $flatValue =
"string(" . mb_strlen( $value ) .
")";
407 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
409 $paramString .=
"$key={$flatValue}";
414 foreach ( $this->metadata as $key => $value ) {
415 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
416 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
421 if ( is_object( $this->title ) ) {
422 $s .=
' ' . $this->title->getPrefixedDBkey();
424 if ( $paramString !=
'' ) {
425 $s .=
" $paramString";
427 if ( $metaString !=
'' ) {
428 $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().