X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fjobqueue%2FJob.php;h=bbd0ddb5f8dffd327116779b2afa8e3471174864;hb=3599ebf004cee683b7d90591c2422f3b7ff54c84;hp=48d38d9c49e07af2679465a27228122b99f02c36;hpb=601519ee36462faabacf4547c9aefaf7e8726476;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index 48d38d9c49..bbd0ddb5f8 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -92,6 +92,10 @@ abstract class Job implements IJobSpecification { // expensive jobs may set this to true $this->removeDuplicates = false; + + if ( !isset( $this->params['requestId'] ) ) { + $this->params['requestId'] = WebRequest::getRequestId(); + } } /** @@ -152,6 +156,18 @@ abstract class Job implements IJobSpecification { : null; } + /** + * @return string|null Id of the request that created this job. Follows + * jobs recursively, allowing to track the id of the request that started a + * job when jobs insert jobs which insert other jobs. + * @since 1.27 + */ + public function getRequestId() { + return isset( $this->params['requestId'] ) + ? $this->params['requestId'] + : null; + } + /** * @return int|null UNIX timestamp of when the job was runnable, or null * @since 1.26 @@ -214,6 +230,8 @@ abstract class Job implements IJobSpecification { unset( $info['params']['rootJobTimestamp'] ); // Likewise for jobs with different delay times unset( $info['params']['jobReleaseTimestamp'] ); + // Identical jobs from different requests should count as duplicates + unset( $info['params']['requestId'] ); // Queues pack and hash this array, so normalize the order ksort( $info['params'] ); } @@ -315,14 +333,6 @@ abstract class Job implements IJobSpecification { * @return string */ public function toString() { - $truncFunc = function ( $value ) { - $value = (string)$value; - if ( mb_strlen( $value ) > 1024 ) { - $value = "string(" . mb_strlen( $value ) . ")"; - } - return $value; - }; - $paramString = ''; if ( $this->params ) { foreach ( $this->params as $key => $value ) { @@ -332,14 +342,14 @@ abstract class Job implements IJobSpecification { if ( is_array( $value ) ) { $filteredValue = []; foreach ( $value as $k => $v ) { - if ( is_scalar( $v ) ) { - $filteredValue[$k] = $truncFunc( $v ); + $json = FormatJson::encode( $v ); + if ( $json === false || mb_strlen( $json ) > 512 ) { + $filteredValue[$k] = gettype( $v ) . '(...)'; } else { - $filteredValue = null; - break; + $filteredValue[$k] = $v; } } - if ( $filteredValue && count( $filteredValue ) < 10 ) { + if ( count( $filteredValue ) <= 10 ) { $value = FormatJson::encode( $filteredValue ); } else { $value = "array(" . count( $value ) . ")"; @@ -348,7 +358,12 @@ abstract class Job implements IJobSpecification { $value = "object(" . get_class( $value ) . ")"; } - $paramString .= "$key={$truncFunc( $value )}"; + $flatValue = (string)$value; + if ( mb_strlen( $value ) > 1024 ) { + $flatValue = "string(" . mb_strlen( $value ) . ")"; + } + + $paramString .= "$key={$flatValue}"; } }