73 $jobClasses = MediaWikiServices::getInstance()->getMainConfig()->get(
74 MainConfigNames::JobClasses );
79 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
80 } elseif ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) ) {
93 if ( isset( $jobClasses[
$command] ) ) {
96 if ( is_callable( $handler ) ) {
98 } elseif ( class_exists( $handler ) ) {
99 if ( is_subclass_of( $handler, GenericParameterJob::class ) ) {
113 throw new InvalidArgumentException(
114 "Could not instantiate job '$command': bad spec!"
119 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
132 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
139 throw new InvalidArgumentException(
'$params must be an array' );
144 !isset(
$params[
'namespace'] ) &&
149 $params[
'namespace'] = $page->getNamespace();
150 $params[
'title'] = $page->getDBkey();
154 $this->params =
$params + [
'requestId' => WebRequest::getRequestId() ];
156 if ( $this->title ===
null ) {
158 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
171 return ( $this->executionFlags & $flag ) === $flag;
194 return $this->params;
204 if ( $field ===
null ) {
205 return $this->metadata;
208 return $this->metadata[$field] ??
null;
220 if ( $value ===
null ) {
221 unset( $this->metadata[$field] );
223 $this->metadata[$field] = $value;
235 return isset( $this->params[
'jobReleaseTimestamp'] )
245 return isset( $this->metadata[
'timestamp'] )
255 return $this->params[
'requestId'] ??
null;
280 return $this->removeDuplicates;
314 if ( is_array( $info[
'params'] ) ) {
316 unset( $info[
'params'][
'rootJobSignature'] );
317 unset( $info[
'params'][
'rootJobTimestamp'] );
319 unset( $info[
'params'][
'jobReleaseTimestamp'] );
321 unset( $info[
'params'][
'requestId'] );
323 ksort( $info[
'params'] );
350 'rootJobIsSelf' =>
true,
351 'rootJobSignature' => sha1( $key ),
364 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
365 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
376 return isset( $this->params[
'rootJobSignature'] )
377 && isset( $this->params[
'rootJobTimestamp'] );
386 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
396 $this->teardownCallbacks[] = $callback;
404 foreach ( $this->teardownCallbacks as $callback ) {
405 call_user_func( $callback, $status );
415 if ( $this->params ) {
416 foreach ( $this->params as $key => $value ) {
417 if ( $paramString !=
'' ) {
420 if ( is_array( $value ) ) {
422 foreach ( $value as $k => $v ) {
423 $json = FormatJson::encode( $v );
424 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
425 $filteredValue[$k] = gettype( $v ) .
'(...)';
427 $filteredValue[$k] = $v;
430 if ( count( $filteredValue ) <= 10 ) {
431 $value = FormatJson::encode( $filteredValue );
433 $value =
"array(" . count( $value ) .
")";
435 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
436 $value =
"object(" . get_class( $value ) .
")";
439 $flatValue = (string)$value;
440 if ( mb_strlen( $flatValue ) > 1024 ) {
441 $flatValue =
"string(" . mb_strlen( $value ) .
")";
444 $paramString .=
"$key={$flatValue}";
449 foreach ( $this->metadata as $key => $value ) {
450 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
451 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
456 if ( is_object( $this->title ) ) {
457 $s .=
' ' . $this->title->getPrefixedDBkey();
459 if ( $paramString !=
'' ) {
460 $s .=
" $paramString";
462 if ( $metaString !=
'' ) {
463 $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)
A class containing constants representing the names of configuration variables.
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