Merge "Accessibility: Don't arbitrarily override role"
[lhc/web/wiklou.git] / includes / job / JobQueue.php
index 17a1338..aa47432 100644 (file)
@@ -96,7 +96,7 @@ abstract class JobQueue {
         */
        final public static function factory( array $params ) {
                $class = $params['class'];
-               if ( !MWInit::classExists( $class ) ) {
+               if ( !class_exists( $class ) ) {
                        throw new MWException( "Invalid job queue class '$class'." );
                }
                $obj = new $class( $params );
@@ -121,23 +121,37 @@ abstract class JobQueue {
        }
 
        /**
-        * @return string One of (random, timestamp, fifo)
+        * @return string One of (random, timestamp, fifo, undefined)
         */
        final public function getOrder() {
                return $this->order;
        }
 
        /**
-        * @return Array Subset of (random, timestamp, fifo)
+        * @return bool Whether delayed jobs are enabled
+        * @since 1.22
+        */
+       final public function delayedJobsEnabled() {
+               return $this->checkDelay;
+       }
+
+       /**
+        * Get the allowed queue orders for configuration validation
+        *
+        * @return Array Subset of (random, timestamp, fifo, undefined)
         */
        abstract protected function supportedOrders();
 
        /**
-        * @return string One of (random, timestamp, fifo)
+        * Get the default queue order to use if configuration does not specify one
+        *
+        * @return string One of (random, timestamp, fifo, undefined)
         */
        abstract protected function optimalOrder();
 
        /**
+        * Find out if delayed jobs are supported for configuration validation
+        *
         * @return boolean Whether delayed jobs are supported
         */
        protected function supportsDelayedJobs() {
@@ -338,7 +352,7 @@ abstract class JobQueue {
                // Flag this job as an old duplicate based on its "root" job...
                try {
                        if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
-                               wfIncrStats( 'job-pop-duplicate' );
+                               JobQueue::incrStats( 'job-pop-duplicate', $this->type );
                                $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
                        }
                } catch ( MWException $e ) {} // don't lose jobs over this
@@ -493,6 +507,28 @@ abstract class JobQueue {
                return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
        }
 
+       /**
+        * Deleted all unclaimed and delayed jobs from the queue
+        *
+        * @return bool Success
+        * @throws MWException
+        * @since 1.22
+        */
+       final public function delete() {
+               wfProfileIn( __METHOD__ );
+               $res = $this->doDelete();
+               wfProfileOut( __METHOD__ );
+               return $res;
+       }
+
+       /**
+        * @see JobQueue::delete()
+        * @return bool Success
+        */
+       protected function doDelete() {
+               throw new MWException( "This method is not implemented." );
+       }
+
        /**
         * Wait for any slaves or backup servers to catch up.
         *
@@ -561,7 +597,7 @@ abstract class JobQueue {
        /**
         * Get an iterator to traverse over all available jobs in this queue.
         * 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.
+        * Note: results may be stale if the queue is concurrently modified.
         *
         * @return Iterator
         * @throws MWException
@@ -570,7 +606,7 @@ 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.
+        * Note: results may be stale if the queue is concurrently modified.
         *
         * @return Iterator
         * @throws MWException
@@ -580,6 +616,19 @@ abstract class JobQueue {
                return new ArrayIterator( array() ); // not implemented
        }
 
+       /**
+        * Call wfIncrStats() for the queue overall and for the queue type
+        *
+        * @param string $key Event type
+        * @param string $type Job type
+        * @param integer $delta
+        * @since 1.22
+        */
+       public static function incrStats( $key, $type, $delta = 1 ) {
+               wfIncrStats( $key, $delta );
+               wfIncrStats( "{$key}-{$type}", $delta );
+       }
+
        /**
         * Namespace the queue with a key to isolate it for testing
         *