From d6d77e9c6ad71e263bc1c1c82558f7fb72f5ddf9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 3 Apr 2013 13:51:02 -0700 Subject: [PATCH] Added Job::hasRootJobParams() convenience function. * Added a missing @since tag. Change-Id: I887d55074007551040eee486dbb9e8e44106e5a9 --- includes/job/Job.php | 18 +++++++++++++++++- includes/job/JobQueue.php | 16 ++++++---------- includes/job/JobQueueRedis.php | 9 ++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/includes/job/Job.php b/includes/job/Job.php index c6787a0ba9..64925f724a 100644 --- a/includes/job/Job.php +++ b/includes/job/Job.php @@ -202,7 +202,10 @@ abstract class Job { } /** - * Subclasses may need to override this to make duplication detection work + * Subclasses may need to override this to make duplication detection work. + * The resulting map conveys everything that makes the job unique. This is + * only checked if ignoreDuplicates() returns true, meaning that duplicate + * jobs are supposed to be ignored. * * @return Array Map of key/values * @since 1.21 @@ -225,6 +228,7 @@ abstract class Job { } /** + * @see JobQueue::deduplicateRootJob() * @param string $key A key that identifies the task * @return Array * @since 1.21 @@ -237,7 +241,9 @@ abstract class Job { } /** + * @see JobQueue::deduplicateRootJob() * @return Array + * @since 1.21 */ public function getRootJobParams() { return array( @@ -250,6 +256,16 @@ abstract class Job { ); } + /** + * @see JobQueue::deduplicateRootJob() + * @return bool + * @since 1.22 + */ + public function hasRootJobParams() { + return isset( $this->params['rootJobSignature'] ) + && isset( $this->params['rootJobTimestamp'] ); + } + /** * Insert a single job into the queue. * @return bool true on success diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 6533abd2b7..17a1338f67 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -427,12 +427,11 @@ abstract class JobQueue { protected function doDeduplicateRootJob( Job $job ) { global $wgMemc; - $params = $job->getParams(); - if ( !isset( $params['rootJobSignature'] ) ) { - throw new MWException( "Cannot register root job; missing 'rootJobSignature'." ); - } elseif ( !isset( $params['rootJobTimestamp'] ) ) { - throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." ); + if ( !$job->hasRootJobParams() ) { + throw new MWException( "Cannot register root job; missing parameters." ); } + $params = $job->getRootJobParams(); + $key = $this->getRootJobCacheKey( $params['rootJobSignature'] ); // Callers should call batchInsert() and then this function so that if the insert // fails, the de-duplication registration will be aborted. Since the insert is @@ -473,13 +472,10 @@ abstract class JobQueue { protected function doIsRootJobOldDuplicate( Job $job ) { global $wgMemc; - $params = $job->getParams(); - if ( !isset( $params['rootJobSignature'] ) ) { + if ( !$job->hasRootJobParams() ) { return false; // job has no de-deplication info - } elseif ( !isset( $params['rootJobTimestamp'] ) ) { - trigger_error( "Cannot check root job; missing 'rootJobTimestamp'." ); - return false; } + $params = $job->getRootJobParams(); // Get the last time this root job was enqueued $timestamp = $wgMemc->get( $this->getRootJobCacheKey( $params['rootJobSignature'] ) ); diff --git a/includes/job/JobQueueRedis.php b/includes/job/JobQueueRedis.php index c57081e77f..26a9b7295d 100644 --- a/includes/job/JobQueueRedis.php +++ b/includes/job/JobQueueRedis.php @@ -441,12 +441,11 @@ LUA; * @throws MWException */ protected function doDeduplicateRootJob( Job $job ) { - $params = $job->getParams(); - if ( !isset( $params['rootJobSignature'] ) ) { - throw new MWException( "Cannot register root job; missing 'rootJobSignature'." ); - } elseif ( !isset( $params['rootJobTimestamp'] ) ) { - throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." ); + if ( !$job->hasRootJobParams() ) { + throw new MWException( "Cannot register root job; missing parameters." ); } + $params = $job->getRootJobParams(); + $key = $this->getRootJobCacheKey( $params['rootJobSignature'] ); $conn = $this->getConnection(); -- 2.20.1