X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=blobdiff_plain;f=maintenance%2FnextJobDB.php;h=6af5cbecec46b2beb034cb143c4cc264d8a19cf3;hb=1c9773bd015adbf8aedb3b1777f0e087906baf6f;hp=fde6b49ec26f17d7b889de778aedf303930b4d46;hpb=ceedb37941702f54766b107aee86e28559868304;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index fde6b49ec2..6af5cbecec 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -6,71 +6,55 @@ * @ingroup Maintenance */ -require_once( "Maintenance.php" ); +$options = array( 'type' ); -class nextJobDB extends Maintenance { - public function __construct() { - parent::__construct(); - $this->mDescription = "Pick a database that has pending jobs"; - $this->addParam( 'type', "The type of job to search for", false, true ); - } - public function execute() { - global $wgMemc; - $type = $this->getParam( 'type', false ); - $mckey = $type === false - ? "jobqueue:dbs" - : "jobqueue:dbs:$type"; - $pendingDBs = $wgMemcKey->get( $mckey ); - - # If we didn't get it from the cache - if( !$pendingDBs ) { - $pendingDBs = $this->getPendingDbs( $type ); - $wgMemc->get( $mckey, $pendingDBs, 300 ) - } - # If we've got a pending job in a db, display it. - if ( $pendingDBs ) { - $this->output( $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)] ); - } +require_once( 'commandLine.inc' ); + +$type = isset($options['type']) + ? $options['type'] + : false; + +$mckey = $type === false + ? "jobqueue:dbs" + : "jobqueue:dbs:$type"; + +$pendingDBs = $wgMemc->get( $mckey ); +if ( !$pendingDBs ) { + $pendingDBs = array(); + # Cross-reference DBs by master DB server + $dbsByMaster = array(); + foreach ( $wgLocalDatabases as $db ) { + $lb = wfGetLB( $db ); + $dbsByMaster[$lb->getServerName(0)][] = $db; } - - /** - * Get all databases that have a pending job - * @param $type String Job type - * @return array - */ - private function getPendingDbs( $type ) { - $pendingDBs = array(); - # Cross-reference DBs by master DB server - $dbsByMaster = array(); - foreach ( $wgLocalDatabases as $db ) { - $lb = wfGetLB( $db ); - $dbsByMaster[$lb->getServerName(0)][] = $db; - } - - foreach ( $dbsByMaster as $master => $dbs ) { - $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] ); - $stype = $dbConn->addQuotes($type); - $jobTable = $dbConn->getTable( 'job' ); - - # Padding row for MySQL bug - $sql = "(SELECT '-------------------------------------------')"; - foreach ( $dbs as $dbName ) { - if ( $sql != '' ) { - $sql .= ' UNION '; - } - if ($type === false) - $sql .= "(SELECT '$dbName' FROM `$dbName`.$jobTable LIMIT 1)"; - else - $sql .= "(SELECT '$dbName' FROM `$dbName`.$jobTable WHERE job_cmd=$stype LIMIT 1)"; - } - $res = $dbConn->query( $sql, __METHOD__ ); - $row = $dbConn->fetchRow( $res ); // discard padding row - while ( $row = $dbConn->fetchRow( $res ) ) { - $pendingDBs[] = $row[0]; + + foreach ( $dbsByMaster as $master => $dbs ) { + $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] ); + $stype = $dbConn->addQuotes($type); + + # Padding row for MySQL bug + $sql = "(SELECT '-------------------------------------------')"; + foreach ( $dbs as $dbName ) { + if ( $sql != '' ) { + $sql .= ' UNION '; } + if ($type === false) + $sql .= "(SELECT '$dbName' FROM `$dbName`.job LIMIT 1)"; + else + $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd=$stype LIMIT 1)"; + } + $res = $dbConn->query( $sql, 'nextJobDB.php' ); + $row = $dbConn->fetchRow( $res ); // discard padding row + while ( $row = $dbConn->fetchRow( $res ) ) { + $pendingDBs[] = $row[0]; } } + + $wgMemc->set( $mckey, $pendingDBs, 300 ); } -$maintClass = "nextJobDb"; -require_once( DO_MAINTENANCE ); +if ( $pendingDBs ) { + echo $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)]; +} + +