From fb69ee48d33b349fd63e363e0e25770aab17b48f Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 28 May 2012 10:20:19 +0200 Subject: [PATCH] (bug 37072) - prevents infinite job loop nextJob.php does not honor jobs types being excluded from the default job queue by using $wgJobTypesExcludedFromDefaultQueue. Since those jobs can never get processed, nextJob.php will always return a database which might produce a nasty infinite loop while trying to process the whole queue. Job::pop did take in account wgJobTypesExcludedFromDefaultQueue to filter the jobs out. So this patch factor out the code in a new method and uses it for nextJob.php. Change-Id: I15197ffcca00f229c9004e2abd87e009bc40f384 --- includes/job/JobQueue.php | 30 +++++++++++++++++++++++------- maintenance/nextJobDB.php | 3 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 00652473cb..a3493b4a1a 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -113,7 +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 ); @@ -124,12 +123,9 @@ abstract class Job { 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' ); @@ -318,6 +314,26 @@ abstract class Job { 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 *------------------------------------------------------------------------*/ diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index 67aa3088c2..d9bd3b8880 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -94,11 +94,12 @@ class nextJobDB extends Maintenance { $lb = wfGetLB( $dbName ); $db = $lb->getConnection( DB_MASTER, array(), $dbName ); if ( $type === false ) { - $conds = array(); + $conds = JobQueue::defaultQueueConditions( ); } else { $conds = array( 'job_cmd' => $type ); } + $exists = (bool) $db->selectField( 'job', '1', $conds, __METHOD__ ); $lb->reuseConnection( $db ); return $exists; -- 2.20.1