69 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
70 } elseif ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) ) {
86 if ( is_callable( $handler ) ) {
88 } elseif ( class_exists( $handler ) ) {
89 if ( is_subclass_of( $handler, GenericParameterJob::class ) ) {
103 throw new InvalidArgumentException(
104 "Could not instantiate job '$command': bad spec!"
109 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
120 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
127 throw new InvalidArgumentException(
'$params must be an array' );
132 !isset(
$params[
'namespace'] ) &&
142 $this->params =
$params + [
'requestId' => WebRequest::getRequestId() ];
144 if ( $this->title ===
null ) {
146 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
155 return ( $this->executionFlags & $flag ) === $flag;
185 if ( $field ===
null ) {
189 return $this->metadata[$field] ??
null;
200 if ( $value ===
null ) {
201 unset( $this->metadata[$field] );
203 $this->metadata[$field] = $value;
214 return isset( $this->params[
'jobReleaseTimestamp'] )
224 return isset( $this->metadata[
'timestamp'] )
230 return $this->params[
'requestId'] ??
null;
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 ),
323 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
324 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
334 return isset( $this->params[
'rootJobSignature'] )
335 && isset( $this->params[
'rootJobTimestamp'] );
343 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
353 $this->teardownCallbacks[] = $callback;
357 foreach ( $this->teardownCallbacks as $callback ) {
358 call_user_func( $callback, $status );
364 if ( $this->params ) {
365 foreach ( $this->params as $key => $value ) {
366 if ( $paramString !=
'' ) {
369 if ( is_array( $value ) ) {
371 foreach ( $value as $k => $v ) {
372 $json = FormatJson::encode( $v );
373 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
374 $filteredValue[$k] = gettype( $v ) .
'(...)';
376 $filteredValue[$k] = $v;
379 if ( count( $filteredValue ) <= 10 ) {
380 $value = FormatJson::encode( $filteredValue );
382 $value =
"array(" . count( $value ) .
")";
384 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
385 $value =
"object(" . get_class( $value ) .
")";
388 $flatValue = (string)$value;
389 if ( mb_strlen( $value ) > 1024 ) {
390 $flatValue =
"string(" . mb_strlen( $value ) .
")";
393 $paramString .=
"$key={$flatValue}";
398 foreach ( $this->metadata as $key => $value ) {
399 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
400 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
405 if ( is_object( $this->title ) ) {
406 $s .=
" {$this->title->getPrefixedDBkey()}";
408 if ( $paramString !=
'' ) {
409 $s .=
" $paramString";
411 if ( $metaString !=
'' ) {
412 $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.
$wgJobClasses['replaceText']
Class to both describe a background job and handle jobs.
setMetadata( $field, $value)
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.
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.
__construct( $command, $params=null)
Represents a title within MediaWiki.
getNamespace()
Get the namespace index, i.e.
getDBkey()
Get the main part with underscores.
Job that has a run() method and metadata accessors for JobQueue::pop() and JobQueue::ack()
if(count( $args)< 1) $job