Merge "[JobQueue] Try to cut down on waitForBackups() calls in runJobs.php."
[lhc/web/wiklou.git] / includes / job / JobQueueGroup.php
index 32c881f..351c71a 100644 (file)
@@ -37,7 +37,7 @@ class JobQueueGroup {
        protected $wiki; // string; wiki ID
 
        const TYPE_DEFAULT = 1; // integer; jobs popped by default
-       const TYPE_ANY     = 2; // integer; any job
+       const TYPE_ANY = 2; // integer; any job
 
        const USE_CACHE = 1; // integer; use process or persistent cache
 
@@ -46,7 +46,7 @@ class JobQueueGroup {
        const CACHE_VERSION = 1; // integer; cache version
 
        /**
-        * @param $wiki string Wiki ID
+        * @param string $wiki Wiki ID
         */
        protected function __construct( $wiki ) {
                $this->wiki = $wiki;
@@ -54,7 +54,7 @@ class JobQueueGroup {
        }
 
        /**
-        * @param $wiki string Wiki ID
+        * @param string $wiki Wiki ID
         * @return JobQueueGroup
         */
        public static function singleton( $wiki = false ) {
@@ -75,8 +75,10 @@ class JobQueueGroup {
        }
 
        /**
+        * Get the job queue object for a given queue type
+        *
         * @param $type string
-        * @return JobQueue Job queue object for a given queue type
+        * @return JobQueue
         */
        public function get( $type ) {
                global $wgJobTypeConf;
@@ -93,7 +95,9 @@ class JobQueueGroup {
 
        /**
         * Insert jobs into the respective queues of with the belong.
-        * This inserts the jobs into the queue specified by $wgJobTypeConf.
+        *
+        * This inserts the jobs into the queue specified by $wgJobTypeConf
+        * and updates the aggregate job queue information cache as needed.
         *
         * @param $jobs Job|array A single Job or a list of Jobs
         * @throws MWException
@@ -133,6 +137,9 @@ class JobQueueGroup {
        /**
         * Pop a job off one of the job queues
         *
+        * This pops a job off a queue as specified by $wgJobTypeConf and
+        * updates the aggregate job queue information cache as needed.
+        *
         * @param $qtype integer|string JobQueueGroup::TYPE_DEFAULT or type string
         * @param $flags integer Bitfield of JobQueueGroup::USE_* constants
         * @return Job|bool Returns false on failure
@@ -194,6 +201,25 @@ class JobQueueGroup {
                return $this->get( $job->getType() )->deduplicateRootJob( $job );
        }
 
+       /**
+        * Wait for any slaves or backup queue servers to catch up.
+        *
+        * This does nothing for certain queue classes.
+        *
+        * @return void
+        * @throws MWException
+        */
+       public function waitForBackups() {
+               global $wgJobTypeConf;
+
+               wfProfileIn( __METHOD__ );
+               // Try to avoid doing this more than once per queue storage medium
+               foreach ( $wgJobTypeConf as $type => $conf ) {
+                       $this->get( $type )->waitForBackups();
+               }
+               wfProfileOut( __METHOD__ );
+       }
+
        /**
         * Get the list of queue types
         *
@@ -229,6 +255,23 @@ class JobQueueGroup {
                return $types;
        }
 
+       /**
+        * Check if jobs should not be popped of a queue right now.
+        * This is only used for performance, such as to avoid spamming
+        * the queue with many sub-jobs before they actually get run.
+        *
+        * @param $type string
+        * @return bool
+        */
+       public function isQueueDeprioritized( $type ) {
+               if ( $type === 'refreshLinks2' ) {
+                       // Don't keep converting refreshLinks2 => refreshLinks jobs if the
+                       // later jobs have not been done yet. This helps throttle queue spam.
+                       return !$this->get( 'refreshLinks' )->isEmpty();
+               }
+               return false;
+       }
+
        /**
         * Execute any due periodic queue maintenance tasks for all queues.
         *
@@ -283,6 +326,10 @@ class JobQueueGroup {
                return $count;
        }
 
+       /**
+        * @param $name string
+        * @return mixed
+        */
        private function getCachedConfigVar( $name ) {
                global $wgConf, $wgMemc;