23use InvalidArgumentException;
80 return $factory->newJob( ...func_get_args() );
94 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
101 throw new InvalidArgumentException(
'$params must be an array' );
106 !isset(
$params[
'namespace'] ) &&
111 $params[
'namespace'] = $page->getNamespace();
112 $params[
'title'] = $page->getDBkey();
117 'requestId' => Telemetry::getInstance()->getRequestId(),
120 if ( $this->title ===
null ) {
122 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
135 return ( $this->executionFlags & $flag ) === $flag;
168 if ( $field ===
null ) {
172 return $this->metadata[$field] ??
null;
184 if ( $value ===
null ) {
185 unset( $this->metadata[$field] );
187 $this->metadata[$field] = $value;
199 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
200 return $time ? (int)$time :
null;
209 return $time ? (int)$time :
null;
217 return $this->params[
'requestId'] ??
null;
276 if ( is_array( $info[
'params'] ) ) {
278 unset( $info[
'params'][
'rootJobSignature'] );
279 unset( $info[
'params'][
'rootJobTimestamp'] );
281 unset( $info[
'params'][
'jobReleaseTimestamp'] );
283 unset( $info[
'params'][
'requestId'] );
285 ksort( $info[
'params'] );
312 'rootJobIsSelf' =>
true,
313 'rootJobSignature' => sha1( $key ),
326 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
327 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
338 return isset( $this->params[
'rootJobSignature'] )
339 && isset( $this->params[
'rootJobTimestamp'] );
348 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
358 $this->teardownCallbacks[] = $callback;
366 foreach ( $this->teardownCallbacks as $callback ) {
367 $callback( $status );
377 if ( $this->params ) {
378 foreach ( $this->params as $key => $value ) {
379 if ( $paramString !=
'' ) {
382 if ( is_array( $value ) ) {
384 foreach ( $value as $k => $v ) {
385 $json = FormatJson::encode( $v );
386 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
387 $filteredValue[$k] = get_debug_type( $v ) .
'(...)';
389 $filteredValue[$k] = $v;
392 if ( count( $filteredValue ) <= 10 ) {
393 $value = FormatJson::encode( $filteredValue );
395 $value =
"array(" . count( $value ) .
")";
397 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
398 $value = get_debug_type( $value );
401 $flatValue = (string)$value;
402 if ( mb_strlen( $flatValue ) > 1024 ) {
403 $flatValue =
"string(" . mb_strlen( $value ) .
")";
408 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
410 $paramString .=
"$key={$flatValue}";
415 foreach ( $this->metadata as $key => $value ) {
416 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
417 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
422 if ( is_object( $this->title ) ) {
423 $s .=
' ' . $this->title->getPrefixedDBkey();
425 if ( $paramString !=
'' ) {
426 $s .=
" $paramString";
428 if ( $metaString !=
'' ) {
429 $s .=
" ($metaString)";
449class_alias( Job::class,
'Job' );
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.