Added Job::hasRootJobParams() convenience function.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 3 Apr 2013 20:51:02 +0000 (13:51 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 3 Apr 2013 20:54:27 +0000 (13:54 -0700)
* Added a missing @since tag.

Change-Id: I887d55074007551040eee486dbb9e8e44106e5a9

includes/job/Job.php
includes/job/JobQueue.php
includes/job/JobQueueRedis.php

index c6787a0..64925f7 100644 (file)
@@ -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
index 6533abd..17a1338 100644 (file)
@@ -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'] ) );
index c57081e..26a9b72 100644 (file)
@@ -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();