From 222b01f5169f1c7e69762e0e8904c24f78f71882 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 28 Jul 2010 11:52:48 +0200 Subject: update to MediaWiki 1.16.0 --- includes/JobQueue.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'includes/JobQueue.php') diff --git a/includes/JobQueue.php b/includes/JobQueue.php index afa757d7..4ab5eac6 100644 --- a/includes/JobQueue.php +++ b/includes/JobQueue.php @@ -46,16 +46,20 @@ abstract class Job { * actually find a job; it may be adversely affected by concurrent job * runners. */ - static function pop_type($type) { + static function pop_type( $type ) { wfProfilein( __METHOD__ ); $dbw = wfGetDB( DB_MASTER ); + $row = $dbw->selectRow( + 'job', + '*', + array( 'job_cmd' => $type ), + __METHOD__, + array( 'LIMIT' => 1 ) + ); - $row = $dbw->selectRow( 'job', '*', array( 'job_cmd' => $type ), __METHOD__, - array( 'LIMIT' => 1 )); - - if ($row === false) { + if ( $row === false ) { wfProfileOut( __METHOD__ ); return false; } @@ -64,7 +68,7 @@ abstract class Job { $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); $affected = $dbw->affectedRows(); - if ($affected == 0) { + if ( $affected == 0 ) { wfProfileOut( __METHOD__ ); return false; } @@ -75,7 +79,7 @@ abstract class Job { $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); - $dbw->immediateCommit(); + $dbw->commit(); wfProfileOut( __METHOD__ ); return $job; @@ -84,10 +88,10 @@ abstract class Job { /** * Pop a job off the front of the queue * - * @param $offset Number of jobs to skip + * @param $offset Integer: Number of jobs to skip * @return Job or false if there's no jobs */ - static function pop($offset=0) { + static function pop( $offset = 0 ) { wfProfileIn( __METHOD__ ); $dbr = wfGetDB( DB_SLAVE ); @@ -100,17 +104,18 @@ abstract class Job { */ $row = $dbr->selectRow( 'job', '*', "job_id >= ${offset}", __METHOD__, - array( 'ORDER BY' => 'job_id', 'LIMIT' => 1 )); + array( 'ORDER BY' => 'job_id', 'LIMIT' => 1 ) ); // Refetching without offset is needed as some of job IDs could have had delayed commits // and have lower IDs than jobs already executed, blame concurrency :) // - if ( $row === false) { - if ($offset!=0) + if ( $row === false ) { + if ( $offset != 0 ) { $row = $dbr->selectRow( 'job', '*', '', __METHOD__, - array( 'ORDER BY' => 'job_id', 'LIMIT' => 1 )); + array( 'ORDER BY' => 'job_id', 'LIMIT' => 1 ) ); + } - if ($row === false ) { + if ( $row === false ) { wfProfileOut( __METHOD__ ); return false; } @@ -121,7 +126,7 @@ abstract class Job { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); $affected = $dbw->affectedRows(); - $dbw->immediateCommit(); + $dbw->commit(); if ( !$affected ) { // Failed, someone else beat us to it @@ -135,7 +140,7 @@ abstract class Job { } // Get the random row $row = $dbw->selectRow( 'job', '*', - 'job_id >= ' . mt_rand( $row->minjob, $row->maxjob ), __METHOD__ ); + 'job_id >= ' . mt_rand( $row->minjob, $row->maxjob ), __METHOD__ ); if ( $row === false ) { // Random job gone before we got the chance to select it // Give up @@ -145,7 +150,7 @@ abstract class Job { // Delete the random row $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); $affected = $dbw->affectedRows(); - $dbw->immediateCommit(); + $dbw->commit(); if ( !$affected ) { // Random job gone before we exclusively deleted it @@ -267,12 +272,13 @@ abstract class Job { return; } } - $fields['job_id'] = $dbw->nextSequenceValue( 'job_job_id_seq' ); $dbw->insert( 'job', $fields, __METHOD__ ); } protected function insertFields() { + $dbw = wfGetDB( DB_MASTER ); return array( + 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), 'job_cmd' => $this->command, 'job_namespace' => $this->title->getNamespace(), 'job_title' => $this->title->getDBkey(), -- cgit v1.2.2