Small doc fix to JobQueueRedis.
[lhc/web/wiklou.git] / includes / job / JobQueue.php
index 9c152cd..17a1338 100644 (file)
@@ -36,7 +36,8 @@ abstract class JobQueue {
        protected $maxTries; // integer; maximum number of times to try a job
        protected $checkDelay; // boolean; allow delayed jobs
 
-       const QoS_Atomic = 1; // integer; "all-or-nothing" job insertions
+       const QOS_ATOMIC = 1; // integer; "all-or-nothing" job insertions
+       const QoS_Atomic = 1; // integer; "all-or-nothing" job insertions (b/c)
 
        const ROOTJOB_TTL = 2419200; // integer; seconds to remember root jobs (28 days)
 
@@ -237,13 +238,37 @@ abstract class JobQueue {
                return 0; // not implemented
        }
 
+       /**
+        * Get the number of acquired jobs that can no longer be attempted.
+        * Queue classes should use caching if they are any slower without memcached.
+        *
+        * If caching is used, this number might be out of date for a minute.
+        *
+        * @return integer
+        * @throws MWException
+        */
+       final public function getAbandonedCount() {
+               wfProfileIn( __METHOD__ );
+               $res = $this->doGetAbandonedCount();
+               wfProfileOut( __METHOD__ );
+               return $res;
+       }
+
+       /**
+        * @see JobQueue::getAbandonedCount()
+        * @return integer
+        */
+       protected function doGetAbandonedCount() {
+               return 0; // not implemented
+       }
+
        /**
         * Push a single jobs into the queue.
         * This does not require $wgJobClasses to be set for the given job type.
         * Outside callers should use JobQueueGroup::push() instead of this function.
         *
         * @param $jobs Job|Array
-        * @param $flags integer Bitfield (supports JobQueue::QoS_Atomic)
+        * @param $flags integer Bitfield (supports JobQueue::QOS_ATOMIC)
         * @return bool Returns false on failure
         * @throws MWException
         */
@@ -257,7 +282,7 @@ abstract class JobQueue {
         * Outside callers should use JobQueueGroup::push() instead of this function.
         *
         * @param array $jobs List of Jobs
-        * @param $flags integer Bitfield (supports JobQueue::QoS_Atomic)
+        * @param $flags integer Bitfield (supports JobQueue::QOS_ATOMIC)
         * @return bool Returns false on failure
         * @throws MWException
         */
@@ -402,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
@@ -448,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'] ) );
@@ -542,7 +563,7 @@ abstract class JobQueue {
         * This does not include jobs that are currently acquired or delayed.
         * This should only be called on a queue that is no longer being popped.
         *
-        * @return Iterator|Traversable|Array
+        * @return Iterator
         * @throws MWException
         */
        abstract public function getAllQueuedJobs();
@@ -551,12 +572,12 @@ abstract class JobQueue {
         * Get an iterator to traverse over all delayed jobs in this queue.
         * This should only be called on a queue that is no longer being popped.
         *
-        * @return Iterator|Traversable|Array
+        * @return Iterator
         * @throws MWException
         * @since 1.22
         */
        public function getAllDelayedJobs() {
-               return array(); // not implemented
+               return new ArrayIterator( array() ); // not implemented
        }
 
        /**