75 public static function factory( $command, $params = [] ) {
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();
115 $this->params =
$params + [
'requestId' => WebRequest::getRequestId() ];
117 if ( $this->title ===
null ) {
119 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
132 return ( $this->executionFlags & $flag ) === $flag;
140 return $this->command;
155 return $this->params;
165 if ( $field ===
null ) {
166 return $this->metadata;
169 return $this->metadata[$field] ??
null;
181 if ( $value ===
null ) {
182 unset( $this->metadata[$field] );
184 $this->metadata[$field] = $value;
196 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
197 return $time ? (int)$time :
null;
206 return $time ? (int)$time :
null;
214 return $this->params[
'requestId'] ??
null;
239 return $this->removeDuplicates;
273 if ( is_array( $info[
'params'] ) ) {
275 unset( $info[
'params'][
'rootJobSignature'] );
276 unset( $info[
'params'][
'rootJobTimestamp'] );
278 unset( $info[
'params'][
'jobReleaseTimestamp'] );
280 unset( $info[
'params'][
'requestId'] );
282 ksort( $info[
'params'] );
309 'rootJobIsSelf' =>
true,
310 'rootJobSignature' => sha1( $key ),
323 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
324 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
335 return isset( $this->params[
'rootJobSignature'] )
336 && isset( $this->params[
'rootJobTimestamp'] );
345 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
355 $this->teardownCallbacks[] = $callback;
363 foreach ( $this->teardownCallbacks as $callback ) {
364 call_user_func( $callback, $status );
374 if ( $this->params ) {
375 foreach ( $this->params as $key => $value ) {
376 if ( $paramString !=
'' ) {
379 if ( is_array( $value ) ) {
381 foreach ( $value as $k => $v ) {
382 $json = FormatJson::encode( $v );
383 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
384 $filteredValue[$k] = gettype( $v ) .
'(...)';
386 $filteredValue[$k] = $v;
389 if ( count( $filteredValue ) <= 10 ) {
390 $value = FormatJson::encode( $filteredValue );
392 $value =
"array(" . count( $value ) .
")";
394 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
395 $value =
"object(" . get_class( $value ) .
")";
398 $flatValue = (string)$value;
399 if ( mb_strlen( $flatValue ) > 1024 ) {
400 $flatValue =
"string(" . mb_strlen( $value ) .
")";
405 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
407 $paramString .=
"$key={$flatValue}";
412 foreach ( $this->metadata as $key => $value ) {
413 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
414 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
419 if ( is_object( $this->title ) ) {
420 $s .=
' ' . $this->title->getPrefixedDBkey();
422 if ( $paramString !=
'' ) {
423 $s .=
" $paramString";
425 if ( $metaString !=
'' ) {
426 $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.
Class to both describe a background job and handle jobs.
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()
bool Whether this job can be retried on failure by job runners 1.21
__construct( $command, $params=null)
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()