76 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
77 } elseif ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) ) {
93 if ( is_callable( $handler ) ) {
95 } elseif ( class_exists( $handler ) ) {
96 if ( is_subclass_of( $handler, GenericParameterJob::class ) ) {
110 throw new InvalidArgumentException(
111 "Could not instantiate job '$command': bad spec!"
116 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
129 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
136 throw new InvalidArgumentException(
'$params must be an array' );
141 !isset(
$params[
'namespace'] ) &&
146 $params[
'namespace'] = $page->getNamespace();
147 $params[
'title'] = $page->getDBkey();
151 $this->params =
$params + [
'requestId' => WebRequest::getRequestId() ];
153 if ( $this->title ===
null ) {
155 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
168 return ( $this->executionFlags & $flag ) === $flag;
201 if ( $field ===
null ) {
205 return $this->metadata[$field] ??
null;
217 if ( $value ===
null ) {
218 unset( $this->metadata[$field] );
220 $this->metadata[$field] = $value;
232 return isset( $this->params[
'jobReleaseTimestamp'] )
242 return isset( $this->metadata[
'timestamp'] )
252 return $this->params[
'requestId'] ??
null;
311 if ( is_array( $info[
'params'] ) ) {
313 unset( $info[
'params'][
'rootJobSignature'] );
314 unset( $info[
'params'][
'rootJobTimestamp'] );
316 unset( $info[
'params'][
'jobReleaseTimestamp'] );
318 unset( $info[
'params'][
'requestId'] );
320 ksort( $info[
'params'] );
347 'rootJobIsSelf' =>
true,
348 'rootJobSignature' => sha1( $key ),
361 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
362 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
373 return isset( $this->params[
'rootJobSignature'] )
374 && isset( $this->params[
'rootJobTimestamp'] );
383 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
393 $this->teardownCallbacks[] = $callback;
401 foreach ( $this->teardownCallbacks as $callback ) {
402 call_user_func( $callback, $status );
412 if ( $this->params ) {
413 foreach ( $this->params as $key => $value ) {
414 if ( $paramString !=
'' ) {
417 if ( is_array( $value ) ) {
419 foreach ( $value as $k => $v ) {
420 $json = FormatJson::encode( $v );
421 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
422 $filteredValue[$k] = gettype( $v ) .
'(...)';
424 $filteredValue[$k] = $v;
427 if ( count( $filteredValue ) <= 10 ) {
428 $value = FormatJson::encode( $filteredValue );
430 $value =
"array(" . count( $value ) .
")";
432 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
433 $value =
"object(" . get_class( $value ) .
")";
436 $flatValue = (string)$value;
437 if ( mb_strlen( $flatValue ) > 1024 ) {
438 $flatValue =
"string(" . mb_strlen( $value ) .
")";
441 $paramString .=
"$key={$flatValue}";
446 foreach ( $this->metadata as $key => $value ) {
447 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
448 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
453 if ( is_object( $this->title ) ) {
454 $s .=
" {$this->title->getPrefixedDBkey()}";
456 if ( $paramString !=
'' ) {
457 $s .=
" $paramString";
459 if ( $metaString !=
'' ) {
460 $s .=
" ($metaString)";
$wgJobClasses
Maps jobs to their handlers; extensions can add to this to provide custom jobs.
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)
Represents a title within MediaWiki.
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(count( $args)< 1) $job