From: Aaron Schulz Date: Thu, 31 Jan 2013 03:27:53 +0000 (-0800) Subject: Made nextJobDB.php respect $wgJobTypesExcludedFromDefaultQueue. X-Git-Tag: 1.31.0-rc.0~20836 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=787547975789fd72729ae74af8add87a1a01aa5d;p=lhc%2Fweb%2Fwiklou.git Made nextJobDB.php respect $wgJobTypesExcludedFromDefaultQueue. Change-Id: I22de34fc7be7b701180511fad3c16154ffdf638b --- diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index 16c6070e1c..032d6f9dfb 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -45,7 +45,7 @@ class nextJobDB extends Maintenance { } elseif ( $this->hasOption( 'type' ) ) { $types = array( $this->getOption( 'type' ) ); } else { - $types = false; + $types = JobQueueGroup::singleton()->getDefaultQueueTypes(); } $memcKey = 'jobqueue:dbs:v3'; @@ -82,24 +82,22 @@ class nextJobDB extends Maintenance { do { $again = false; - if ( $types === false ) { - $candidates = call_user_func_array( 'array_merge', $pendingDBs ); - } else { - $candidates = array(); - $possTypes = array_intersect( $types, array_keys( $pendingDBs ) ); - if ( $possTypes ) { - $possTypes = array_values( $possTypes ); - $type = $possTypes[ mt_rand( 0, count( $possTypes ) - 1 ) ]; - $candidates = $pendingDBs[$type]; + $candidates = array(); // list of (type, db) + // Flatten the tree of candidates into a flat list so that a random + // item can be selected, weighing each queue (type/db tuple) equally. + foreach ( $pendingDBs as $type => $dbs ) { + if ( in_array( $type, $types ) ) { + foreach ( $dbs as $db ) { + $candidates[] = array( $type, $db ); + } } } - if ( !$candidates ) { + if ( !count( $candidates ) ) { return; // no jobs for this type } - $candidates = array_values( $candidates ); - $db = $candidates[ mt_rand( 0, count( $candidates ) - 1 ) ]; - if ( !$this->checkJob( $type, $db ) ) { + list( $type, $db ) = $candidates[ mt_rand( 0, count( $candidates ) - 1 ) ]; + if ( !$this->checkJob( $type, $db ) ) { // queue is actually empty? $pendingDBs = $this->delistDB( $pendingDBs, $db, $type ); // Update the cache to remove the outdated information. // Make sure that this does not race (especially with full rebuilds). @@ -125,16 +123,16 @@ class nextJobDB extends Maintenance { } } + /** + * Remove a type/DB entry from the list of queues with jobs + * + * @param $pendingDBs array + * @param $db string + * @param $type string + * @return Array + */ private function delistDB( array $pendingDBs, $db, $type ) { - if ( $type === false ) { - // There are no jobs available in the current database - foreach ( $pendingDBs as $type2 => $dbs ) { - $pendingDBs[$type2] = array_diff( $pendingDBs[$type2], array( $db ) ); - } - } else { - // There are no jobs of this type available in the current database - $pendingDBs[$type] = array_diff( $pendingDBs[$type], array( $db ) ); - } + $pendingDBs[$type] = array_diff( $pendingDBs[$type], array( $db ) ); return $pendingDBs; } @@ -146,17 +144,7 @@ class nextJobDB extends Maintenance { * @return bool */ private function checkJob( $type, $dbName ) { - $group = JobQueueGroup::singleton( $dbName ); - if ( $type === false ) { - foreach ( $group->getDefaultQueueTypes() as $type ) { - if ( !$group->get( $type )->isEmpty() ) { - return true; - } - } - return false; - } else { - return !$group->get( $type )->isEmpty(); - } + return !JobQueueGroup::singleton( $dbName )->get( $type )->isEmpty(); } /**