Merge "Remove hphpc support and deprecate related functions"
[lhc/web/wiklou.git] / includes / job / JobQueue.php
index 41ef443..08d4f39 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
@@ -427,12 +441,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 +486,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'] ) );
@@ -567,7 +577,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();
@@ -576,12 +586,25 @@ 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
+       }
+
+       /**
+        * 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 );
        }
 
        /**