74 public static function factory( $command, $params = [] ) {
75 $factory = MediaWikiServices::getInstance()->getJobFactory();
79 return $factory->newJob( ...func_get_args() );
92 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
99 throw new InvalidArgumentException(
'$params must be an array' );
104 !isset(
$params[
'namespace'] ) &&
109 $params[
'namespace'] = $page->getNamespace();
110 $params[
'title'] = $page->getDBkey();
114 $this->params =
$params + [
'requestId' => WebRequest::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;
154 return $this->params;
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 return isset( $this->params[
'jobReleaseTimestamp'] )
205 return isset( $this->metadata[
'timestamp'] )
215 return $this->params[
'requestId'] ??
null;
240 return $this->removeDuplicates;
274 if ( is_array( $info[
'params'] ) ) {
276 unset( $info[
'params'][
'rootJobSignature'] );
277 unset( $info[
'params'][
'rootJobTimestamp'] );
279 unset( $info[
'params'][
'jobReleaseTimestamp'] );
281 unset( $info[
'params'][
'requestId'] );
283 ksort( $info[
'params'] );
310 'rootJobIsSelf' =>
true,
311 'rootJobSignature' => sha1( $key ),
324 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
325 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
336 return isset( $this->params[
'rootJobSignature'] )
337 && isset( $this->params[
'rootJobTimestamp'] );
346 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
356 $this->teardownCallbacks[] = $callback;
364 foreach ( $this->teardownCallbacks as $callback ) {
365 call_user_func( $callback, $status );
375 if ( $this->params ) {
376 foreach ( $this->params as $key => $value ) {
377 if ( $paramString !=
'' ) {
380 if ( is_array( $value ) ) {
382 foreach ( $value as $k => $v ) {
383 $json = FormatJson::encode( $v );
384 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
385 $filteredValue[$k] = gettype( $v ) .
'(...)';
387 $filteredValue[$k] = $v;
390 if ( count( $filteredValue ) <= 10 ) {
391 $value = FormatJson::encode( $filteredValue );
393 $value =
"array(" . count( $value ) .
")";
395 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
396 $value =
"object(" . get_class( $value ) .
")";
399 $flatValue = (string)$value;
400 if ( mb_strlen( $flatValue ) > 1024 ) {
401 $flatValue =
"string(" . mb_strlen( $value ) .
")";
404 $paramString .=
"$key={$flatValue}";
409 foreach ( $this->metadata as $key => $value ) {
410 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
411 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
416 if ( is_object( $this->title ) ) {
417 $s .=
' ' . $this->title->getPrefixedDBkey();
419 if ( $paramString !=
'' ) {
420 $s .=
" $paramString";
422 if ( $metaString !=
'' ) {
423 $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()