Localisation updates German
[mediawiki.git] / maintenance / nextJobDB.php
blobb9e44939fe58f7cd843c5653cfb1de3da0774e62
1 <?php
3 /*
4 * Pick a database that has pending jobs
5 */
7 $options = array( 'type' );
9 require_once( 'commandLine.inc' );
11 $type = isset($options['type'])
12 ? $options['type']
13 : false;
15 $mckey = $type === false
16 ? "jobqueue:dbs"
17 : "jobqueue:dbs:$type";
19 $pendingDBs = $wgMemc->get( $mckey );
20 if ( !$pendingDBs ) {
21 $pendingDBs = array();
22 # Cross-reference DBs by master DB server
23 $dbsByMaster = array();
24 foreach ( $wgLocalDatabases as $db ) {
25 $lb = wfGetLB( $db );
26 $dbsByMaster[$lb->getServerName(0)][] = $db;
29 foreach ( $dbsByMaster as $master => $dbs ) {
30 $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] );
31 $stype = $dbConn->addQuotes($type);
33 # Padding row for MySQL bug
34 $sql = "(SELECT '-------------------------------------------')";
35 foreach ( $dbs as $dbName ) {
36 if ( $sql != '' ) {
37 $sql .= ' UNION ';
39 if ($type === false)
40 $sql .= "(SELECT '$dbName' FROM `$dbName`.job LIMIT 1)";
41 else
42 $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd=$stype LIMIT 1)";
44 $res = $dbConn->query( $sql, 'nextJobDB.php' );
45 $row = $dbConn->fetchRow( $res ); // discard padding row
46 while ( $row = $dbConn->fetchRow( $res ) ) {
47 $pendingDBs[] = $row[0];
51 $wgMemc->set( $mckey, $pendingDBs, 300 );
54 if ( $pendingDBs ) {
55 echo $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)];