00001 <?php
00009 $options = array( 'type' );
00010
00011 require_once( 'commandLine.inc' );
00012
00013 $type = isset($options['type'])
00014 ? $options['type']
00015 : false;
00016
00017 $mckey = $type === false
00018 ? "jobqueue:dbs"
00019 : "jobqueue:dbs:$type";
00020
00021 $pendingDBs = $wgMemc->get( $mckey );
00022 if ( !$pendingDBs ) {
00023 $pendingDBs = array();
00024 # Cross-reference DBs by master DB server
00025 $dbsByMaster = array();
00026 foreach ( $wgLocalDatabases as $db ) {
00027 $lb = wfGetLB( $db );
00028 $dbsByMaster[$lb->getServerName(0)][] = $db;
00029 }
00030
00031 foreach ( $dbsByMaster as $master => $dbs ) {
00032 $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] );
00033 $stype = $dbConn->addQuotes($type);
00034
00035 # Padding row for MySQL bug
00036 $sql = "(SELECT '-------------------------------------------')";
00037 foreach ( $dbs as $dbName ) {
00038 if ( $sql != '' ) {
00039 $sql .= ' UNION ';
00040 }
00041 if ($type === false)
00042 $sql .= "(SELECT '$dbName' FROM `$dbName`.job LIMIT 1)";
00043 else
00044 $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd=$stype LIMIT 1)";
00045 }
00046 $res = $dbConn->query( $sql, 'nextJobDB.php' );
00047 $row = $dbConn->fetchRow( $res );
00048 while ( $row = $dbConn->fetchRow( $res ) ) {
00049 $pendingDBs[] = $row[0];
00050 }
00051 }
00052
00053 $wgMemc->set( $mckey, $pendingDBs, 300 );
00054 }
00055
00056 if ( $pendingDBs ) {
00057 echo $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)];
00058 }
00059
00060