From: Aaron Schulz Date: Sun, 27 Jan 2013 06:19:17 +0000 (-0800) Subject: Let nextJobDB.php narrow down the type based on a set. X-Git-Tag: 1.31.0-rc.0~20898^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=7eb23ccccd185768bc712608ec9f872c6cc4b671;p=lhc%2Fweb%2Fwiklou.git Let nextJobDB.php narrow down the type based on a set. * This can avoid slower for loops in jobs-loop.sh. Change-Id: I4d686400dcb83a3c64c14a01100ad6b451542f05 --- diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index 17a3f2e078..9b83bf9ca2 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -33,13 +33,21 @@ class nextJobDB extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Pick a database that has pending jobs"; - $this->addOption( 'type', "The type of job to search for", false, true ); + $this->addOption( 'type', "Search by job type", false, true ); + $this->addOption( 'types', "Space separated list of job types to search for", false, true ); } public function execute() { global $wgMemc; - $type = $this->getOption( 'type', false ); + $type = false; // job type required/picked + if ( $this->hasOption( 'types' ) ) { + $types = explode( ' ', $this->getOption( 'types' ) ); + } elseif ( $this->hasOption( 'type' ) ) { + $types = array( $this->getOption( 'type' ) ); + } else { + $types = false; + } $memcKey = 'jobqueue:dbs:v3'; $pendingDbInfo = $wgMemc->get( $memcKey ); @@ -75,15 +83,19 @@ class nextJobDB extends Maintenance { do { $again = false; - if ( $type === false ) { + if ( $types === false ) { $candidates = call_user_func_array( 'array_merge', $pendingDBs ); - } elseif ( isset( $pendingDBs[$type] ) ) { - $candidates = $pendingDBs[$type]; } 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]; + } } if ( !$candidates ) { - return; + return; // no jobs for this type } $candidates = array_values( $candidates ); @@ -112,7 +124,11 @@ class nextJobDB extends Maintenance { } } while ( $again ); - $this->output( $db . "\n" ); + if ( $this->hasOption( 'types' ) ) { + $this->output( $db . " " . $type . "\n" ); + } else { + $this->output( $db . "\n" ); + } } /**