Merge "Automatically deduplicate root jobs on insertion"
[lhc/web/wiklou.git] / includes / jobqueue / Job.php
index b971bd5..f7ef8a9 100644 (file)
@@ -206,15 +206,27 @@ abstract class Job implements IJobSpecification {
        }
 
        /**
+        * Get "root job" parameters for a task
+        *
+        * This is used to no-op redundant jobs, including child jobs of jobs,
+        * as long as the children inherit the root job parameters. When a job
+        * with root job parameters and "rootJobIsSelf" set is pushed, the
+        * deduplicateRootJob() method is automatically called on it. If the
+        * root job is only virtual and not actually pushed (e.g. the sub-jobs
+        * are inserted directly), then call deduplicateRootJob() directly.
+        *
         * @see JobQueue::deduplicateRootJob()
+        *
         * @param string $key A key that identifies the task
         * @return array Map of:
+        *   - rootJobIsSelf    : true
         *   - rootJobSignature : hash (e.g. SHA1) that identifies the task
         *   - rootJobTimestamp : TS_MW timestamp of this instance of the task
         * @since 1.21
         */
        public static function newRootJobParams( $key ) {
                return array(
+                       'rootJobIsSelf'    => true,
                        'rootJobSignature' => sha1( $key ),
                        'rootJobTimestamp' => wfTimestampNow()
                );
@@ -246,6 +258,14 @@ abstract class Job implements IJobSpecification {
                        && isset( $this->params['rootJobTimestamp'] );
        }
 
+       /**
+        * @see JobQueue::deduplicateRootJob()
+        * @return bool Whether this is job is a root job
+        */
+       public function isRootJob() {
+               return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
+       }
+
        /**
         * Insert a single job into the queue.
         * @return bool True on success