9use InvalidArgumentException;
66 return $factory->newJob( ...func_get_args() );
80 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
87 throw new InvalidArgumentException(
'$params must be an array' );
92 !isset(
$params[
'namespace'] ) &&
97 $params[
'namespace'] = $page->getNamespace();
98 $params[
'title'] = $page->getDBkey();
103 'requestId' => Telemetry::getInstance()->getRequestId(),
106 if ( $this->title ===
null ) {
108 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
121 return ( $this->executionFlags & $flag ) === $flag;
154 if ( $field ===
null ) {
158 return $this->metadata[$field] ??
null;
170 if ( $value ===
null ) {
171 unset( $this->metadata[$field] );
173 $this->metadata[$field] = $value;
185 $time =
wfTimestampOrNull( TS_UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
186 return $time ? (int)$time :
null;
195 return $time ? (int)$time :
null;
203 return $this->params[
'requestId'] ??
null;
262 if ( is_array( $info[
'params'] ) ) {
264 unset( $info[
'params'][
'rootJobSignature'] );
265 unset( $info[
'params'][
'rootJobTimestamp'] );
267 unset( $info[
'params'][
'jobReleaseTimestamp'] );
269 unset( $info[
'params'][
'requestId'] );
271 ksort( $info[
'params'] );
298 'rootJobIsSelf' =>
true,
299 'rootJobSignature' => sha1( $key ),
312 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
313 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
324 return isset( $this->params[
'rootJobSignature'] )
325 && isset( $this->params[
'rootJobTimestamp'] );
334 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
344 $this->teardownCallbacks[] = $callback;
352 foreach ( $this->teardownCallbacks as $callback ) {
353 $callback( $status );
363 if ( $this->params ) {
364 foreach ( $this->params as $key => $value ) {
365 if ( $paramString !=
'' ) {
368 if ( is_array( $value ) ) {
370 foreach ( $value as $k => $v ) {
371 $json = FormatJson::encode( $v );
372 if ( $json ===
false || mb_strlen( $json ) > 512 ) {
373 $filteredValue[$k] = get_debug_type( $v ) .
'(...)';
375 $filteredValue[$k] = $v;
378 if ( count( $filteredValue ) <= 10 ) {
379 $value = FormatJson::encode( $filteredValue );
381 $value =
"array(" . count( $value ) .
")";
383 } elseif ( is_object( $value ) && !method_exists( $value,
'__toString' ) ) {
384 $value = get_debug_type( $value );
387 $flatValue = (string)$value;
388 if ( mb_strlen( $flatValue ) > 1024 ) {
389 $flatValue =
"string(" . mb_strlen( $value ) .
")";
394 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
396 $paramString .=
"$key={$flatValue}";
401 foreach ( $this->metadata as $key => $value ) {
402 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
403 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
408 if ( is_object( $this->title ) ) {
409 $s .=
' ' . $this->title->getPrefixedDBkey();
411 if ( $paramString !=
'' ) {
412 $s .=
" $paramString";
414 if ( $metaString !=
'' ) {
415 $s .=
" ($metaString)";
438class_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.