9use InvalidArgumentException;
15use Wikimedia\Timestamp\TimestampFormat as TS;
67 return $factory->newJob( ...func_get_args() );
81 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
88 throw new InvalidArgumentException(
'$params must be an array' );
93 !isset(
$params[
'namespace'] ) &&
98 $params[
'namespace'] = $page->getNamespace();
99 $params[
'title'] = $page->getDBkey();
104 'requestId' => Telemetry::getInstance()->getRequestId(),
107 if ( $this->title ===
null ) {
109 $this->title = ( isset(
$params[
'namespace'] ) && isset(
$params[
'title'] ) )
122 return ( $this->executionFlags & $flag ) === $flag;
155 if ( $field ===
null ) {
159 return $this->metadata[$field] ??
null;
171 if ( $value ===
null ) {
172 unset( $this->metadata[$field] );
174 $this->metadata[$field] = $value;
186 $time =
wfTimestampOrNull( TS::UNIX, $this->params[
'jobReleaseTimestamp'] ??
null );
187 return $time ? (int)$time :
null;
196 return $time ? (int)$time :
null;
204 return $this->params[
'requestId'] ??
null;
263 if ( is_array( $info[
'params'] ) ) {
265 unset( $info[
'params'][
'rootJobSignature'] );
266 unset( $info[
'params'][
'rootJobTimestamp'] );
268 unset( $info[
'params'][
'jobReleaseTimestamp'] );
270 unset( $info[
'params'][
'requestId'] );
272 ksort( $info[
'params'] );
299 'rootJobIsSelf' =>
true,
300 'rootJobSignature' => sha1( $key ),
313 'rootJobSignature' => $this->params[
'rootJobSignature'] ??
null,
314 'rootJobTimestamp' => $this->params[
'rootJobTimestamp'] ?? null
325 return isset( $this->params[
'rootJobSignature'] )
326 && isset( $this->params[
'rootJobTimestamp'] );
335 return $this->
hasRootJobParams() && !empty( $this->params[
'rootJobIsSelf'] );
345 $this->teardownCallbacks[] = $callback;
353 foreach ( $this->teardownCallbacks as $callback ) {
354 $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] = get_debug_type( $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 = get_debug_type( $value );
388 $flatValue = (string)$value;
389 if ( mb_strlen( $flatValue ) > 1024 ) {
390 $flatValue =
"string(" . mb_strlen( $value ) .
")";
395 $flatValue = preg_replace(
'/\s+/',
' ', $flatValue );
397 $paramString .=
"$key={$flatValue}";
402 foreach ( $this->metadata as $key => $value ) {
403 if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
404 $metaString .= ( $metaString ?
",$key=$value" :
"$key=$value" );
409 if ( is_object( $this->title ) ) {
410 $s .=
' ' . $this->title->getPrefixedDBkey();
412 if ( $paramString !=
'' ) {
413 $s .=
" $paramString";
415 if ( $metaString !=
'' ) {
416 $s .=
" ($metaString)";
439class_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.