Merge "(bug 43661) Added test for special link trail case"
[lhc/web/wiklou.git] / includes / job / JobQueue.php
index 19cecb7..a36cf5b 100644 (file)
@@ -49,19 +49,21 @@ abstract class JobQueue {
        /**
         * Get a job queue object of the specified type.
         * $params includes:
-        *   class    : What job class to use (determines job type)
-        *   wiki     : wiki ID of the wiki the jobs are for (defaults to current wiki)
-        *   type     : The name of the job types this queue handles
-        *   order    : Order that pop() selects jobs, one of "fifo", "timestamp" or "random".
-        *              If "fifo" is used, the queue will effectively be FIFO. Note that
-        *              job completion will not appear to be exactly FIFO if there are multiple
-        *              job runners since jobs can take different times to finish once popped.
-        *              If "timestamp" is used, the queue will at least be loosely ordered
-        *              by timestamp, allowing for some jobs to be popped off out of order.
-        *              If "random" is used, pop() will pick jobs in random order. This might be
-        *              useful for improving concurrency depending on the queue storage medium.
-        *   claimTTL : If supported, the queue will recycle jobs that have been popped
-        *              but not acknowledged as completed after this many seconds.
+        *   - class    : What job class to use (determines job type)
+        *   - wiki     : wiki ID of the wiki the jobs are for (defaults to current wiki)
+        *   - type     : The name of the job types this queue handles
+        *   - order    : Order that pop() selects jobs, one of "fifo", "timestamp" or "random".
+        *                If "fifo" is used, the queue will effectively be FIFO. Note that
+        *                job completion will not appear to be exactly FIFO if there are multiple
+        *                job runners since jobs can take different times to finish once popped.
+        *                If "timestamp" is used, the queue will at least be loosely ordered
+        *                by timestamp, allowing for some jobs to be popped off out of order.
+        *                If "random" is used, pop() will pick jobs in random order. This might be
+        *                useful for improving concurrency depending on the queue storage medium.
+        *   - claimTTL : If supported, the queue will recycle jobs that have been popped
+        *                but not acknowledged as completed after this many seconds.
+        *
+        * Queue classes should throw an exception if they do not support the options given.
         *
         * @param $params array
         * @return JobQueue
@@ -94,7 +96,7 @@ abstract class JobQueue {
        }
 
        /**
-        * Quickly check if the queue is empty.
+        * Quickly check if the queue is empty (has no available jobs).
         * Queue classes should use caching if they are any slower without memcached.
         *
         * @return bool
@@ -112,6 +114,44 @@ abstract class JobQueue {
         */
        abstract protected function doIsEmpty();
 
+       /**
+        * Get the number of available jobs in the queue.
+        * Queue classes should use caching if they are any slower without memcached.
+        *
+        * @return integer
+        */
+       final public function getSize() {
+               wfProfileIn( __METHOD__ );
+               $res = $this->doGetSize();
+               wfProfileOut( __METHOD__ );
+               return $res;
+       }
+
+       /**
+        * @see JobQueue::getSize()
+        * @return integer
+        */
+       abstract protected function doGetSize();
+
+       /**
+        * Get the number of acquired jobs (these are temporarily out of the queue).
+        * Queue classes should use caching if they are any slower without memcached.
+        *
+        * @return integer
+        */
+       final public function getAcquiredCount() {
+               wfProfileIn( __METHOD__ );
+               $res = $this->doGetAcquiredCount();
+               wfProfileOut( __METHOD__ );
+               return $res;
+       }
+
+       /**
+        * @see JobQueue::getAcquiredCount()
+        * @return integer
+        */
+       abstract protected function doGetAcquiredCount();
+
        /**
         * Push a batch of jobs into the queue
         *
@@ -128,9 +168,6 @@ abstract class JobQueue {
                }
                wfProfileIn( __METHOD__ );
                $ok = $this->doBatchPush( $jobs, $flags );
-               if ( $ok ) {
-                       wfIncrStats( 'job-insert', count( $jobs ) );
-               }
                wfProfileOut( __METHOD__ );
                return $ok;
        }
@@ -149,9 +186,6 @@ abstract class JobQueue {
        final public function pop() {
                wfProfileIn( __METHOD__ );
                $job = $this->doPop();
-               if ( $job ) {
-                       wfIncrStats( 'job-pop' );
-               }
                wfProfileOut( __METHOD__ );
                return $job;
        }
@@ -163,7 +197,9 @@ abstract class JobQueue {
        abstract protected function doPop();
 
        /**
-        * Acknowledge that a job was completed
+        * Acknowledge that a job was completed.
+        *
+        * This does nothing for certain queue classes or if "claimTTL" is not set.
         *
         * @param $job Job
         * @throws MWException
@@ -210,6 +246,8 @@ abstract class JobQueue {
         * Essentially, the new batch of jobs belong to a new "root job" and the older ones to a
         * previous "root job" for the same task of "update links of pages that use template X".
         *
+        * This does nothing for certain queue classes.
+        *
         * @param $job Job
         * @throws MWException
         * @return bool
@@ -234,7 +272,9 @@ abstract class JobQueue {
        }
 
        /**
-        * Wait for any slaves or backup servers to catch up
+        * Wait for any slaves or backup servers to catch up.
+        *
+        * This does nothing for certain queue classes.
         *
         * @return void
         */