Merge "(bug 37072) - prevents infinite job loop"
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 29 May 2012 20:19:58 +0000 (20:19 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 29 May 2012 20:19:58 +0000 (20:19 +0000)
1  2 
includes/job/JobQueue.php

@@@ -113,7 -113,6 +113,6 @@@ abstract class Job 
         * @return Job or false if there's no jobs
         */
        static function pop( $offset = 0 ) {
-               global $wgJobTypesExcludedFromDefaultQueue;
                wfProfileIn( __METHOD__ );
  
                $dbr = wfGetDB( DB_SLAVE );
                        NB: If random fetch previously was used, offset
                                will always be ahead of few entries
                */
-               $conditions = array();
-               if ( count( $wgJobTypesExcludedFromDefaultQueue ) != 0 ) {
-                       foreach ( $wgJobTypesExcludedFromDefaultQueue as $cmdType ) {
-                               $conditions[] = "job_cmd != " . $dbr->addQuotes( $cmdType );
-                       }
-               }
+               $conditions = self::defaultQueueConditions();
                $offset = intval( $offset );
                $options = array( 'ORDER BY' => 'job_id', 'USE INDEX' => 'PRIMARY' );
  
                $title = Title::makeTitleSafe( $namespace, $dbkey );
  
                if ( is_null( $title ) ) {
 +                      wfProfileOut( __METHOD__ );
                        return false;
                }
  
                wfIncrStats( 'job-insert', count( $jobs ) );
        }
  
+       /**
+        * SQL conditions to apply on most JobQueue queries
+        *
+        * Whenever we exclude jobs types from the default queue, we want to make
+        * sure that queries to the job queue actually ignore them.
+        *
+        * @return array SQL conditions suitable for Database:: methods
+        */
+       static function defaultQueueConditions( ) {
+               global $wgJobTypesExcludedFromDefaultQueue;
+               $conditions = array();
+               if ( count( $wgJobTypesExcludedFromDefaultQueue ) > 0 ) {
+                       foreach ( $wgJobTypesExcludedFromDefaultQueue as $cmdType ) {
+                               $conditions[] = "job_cmd != " . $dbr->addQuotes( $cmdType );
+                       }
+               }
+               return $conditions;
+       }
        /*-------------------------------------------------------------------------
         * Non-static functions
         *------------------------------------------------------------------------*/