* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @todo Make this work on PostgreSQL and maybe other database servers
* @ingroup Maintenance
*/
$this->mDescription = "Pick a database that has pending jobs";
$this->addOption( 'type', "The type of job to search for", false, true );
}
+
public function execute() {
global $wgMemc;
$type = $this->getOption( 'type', false );
? "jobqueue:dbs"
: "jobqueue:dbs:$type";
$pendingDBs = $wgMemc->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 we've got a pending job in a db, display it.
if ( $pendingDBs ) {
$this->output( $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)] );
}
}
-
+
/**
* Get all databases that have a pending job
* @param $type String Job type
$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->tableName( 'job' );
-
+ $stype = $dbConn->addQuotes( $type );
+
# Padding row for MySQL bug
$sql = "(SELECT '-------------------------------------------' as db)";
- foreach ( $dbs as $dbName ) {
+ foreach ( $dbs as $wikiId ) {
if ( $sql != '' ) {
$sql .= ' UNION ';
}
- if ($type === false)
- $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable LIMIT 1)";
+
+ list( $dbName, $tablePrefix ) = wfSplitWikiID( $wikiId );
+ $dbConn->tablePrefix( $tablePrefix );
+ $jobTable = $dbConn->tableName( 'job' );
+
+ if ( $type === false )
+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable LIMIT 1)";
else
- $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable WHERE job_cmd=$stype LIMIT 1)";
+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable WHERE job_cmd=$stype LIMIT 1)";
}
$res = $dbConn->query( $sql, __METHOD__ );
$first = true;