4 * Pick a database that has pending jobs
7 $options = array( 'type' );
9 require_once( 'commandLine.inc' );
11 $type = isset($options['type'])
15 $mckey = $type === false
17 : "jobqueue:dbs:$type";
19 $pendingDBs = $wgMemc->get( $mckey );
21 $pendingDBs = array();
22 # Cross-reference DBs by master DB server
23 $dbsByMaster = array();
24 $defaultMaster = isset( $wgAlternateMaster['DEFAULT'] )
25 ?
$wgAlternateMaster['DEFAULT']
27 foreach ( $wgLocalDatabases as $db ) {
28 if ( isset( $wgAlternateMaster[$db] ) ) {
29 $dbsByMaster[$wgAlternateMaster[$db]][] = $db;
31 $dbsByMaster[$defaultMaster][] = $db;
35 foreach ( $dbsByMaster as $master => $dbs ) {
36 $dbConn = new Database( $master, $wgDBuser, $wgDBpassword, $dbs[0] );
37 $stype = $dbConn->addQuotes($type);
39 # Padding row for MySQL bug
40 $sql = "(SELECT '-------------------------------------------')";
41 foreach ( $dbs as $dbName ) {
46 $sql .= "(SELECT '$dbName' FROM `$dbName`.job LIMIT 1)";
48 $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd=$stype LIMIT 1)";
50 $res = $dbConn->query( $sql, 'nextJobDB.php' );
51 $row = $dbConn->fetchRow( $res ); // discard padding row
52 while ( $row = $dbConn->fetchRow( $res ) ) {
53 $pendingDBs[] = $row[0];
57 $wgMemc->set( $mckey, $pendingDBs, 300 );
61 echo $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)];