X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FJobQueue.php;h=afa757d752ed84f34e1ee6fe777c4edd6dc6059c;hb=418e7767b4e6d27344bd81da8a8ddd319784f4b3;hp=1e9690252a674546181f07e6dc75caf2c02c25fa;hpb=6f53fc41af6d71f67cd5434460afcd8ad07f31bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/JobQueue.php b/includes/JobQueue.php index 1e9690252a..afa757d752 100644 --- a/includes/JobQueue.php +++ b/includes/JobQueue.php @@ -1,13 +1,16 @@ selectRow( 'job', '*', "job_id >= ${offset}", __METHOD__, @@ -124,7 +127,7 @@ abstract class Job { // Failed, someone else beat us to it // Try getting a random row $row = $dbw->selectRow( 'job', array( 'MIN(job_id) as minjob', - 'MAX(job_id) as maxjob' ), "job_id >= $offset", __METHOD__ ); + 'MAX(job_id) as maxjob' ), '1=1', __METHOD__ ); if ( $row === false || is_null( $row->minjob ) || is_null( $row->maxjob ) ) { // No jobs to get wfProfileOut( __METHOD__ ); @@ -160,27 +163,31 @@ abstract class Job { $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); // Remove any duplicates it may have later in the queue + // Deadlock prone section + $dbw->begin(); $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); + $dbw->commit(); wfProfileOut( __METHOD__ ); return $job; } /** - * Create an object of a subclass + * Create the appropriate object to handle a specific job + * + * @param $command String: Job command + * @param $title Title: Associated title + * @param $params Array: Job parameters + * @param $id Int: Job identifier + * @return Job */ static function factory( $command, $title, $params = false, $id = 0 ) { - switch ( $command ) { - case 'refreshLinks': - return new RefreshLinksJob( $title, $params, $id ); - case 'htmlCacheUpdate': - case 'html_cache_update': # BC - return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id ); - case 'sendMail': - return new EmaillingJob($params); - default: - throw new MWException( "Invalid job command \"$command\"" ); + global $wgJobClasses; + if( isset( $wgJobClasses[$command] ) ) { + $class = $wgJobClasses[$command]; + return new $class( $title, $params, $id ); } + throw new MWException( "Invalid job command `{$command}`" ); } static function makeBlob( $params ) { @@ -209,12 +216,23 @@ abstract class Job { * @param $jobs array of Job objects */ static function batchInsert( $jobs ) { - if( count( $jobs ) ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->begin(); - foreach( $jobs as $job ) { - $rows[] = $job->insertFields(); + if( !count( $jobs ) ) { + return; + } + $dbw = wfGetDB( DB_MASTER ); + $rows = array(); + foreach( $jobs as $job ) { + $rows[] = $job->insertFields(); + if ( count( $rows ) >= 50 ) { + # Do a small transaction to avoid slave lag + $dbw->begin(); + $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); + $dbw->commit(); + $rows = array(); } + } + if ( $rows ) { + $dbw->begin(); $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); $dbw->commit(); } @@ -284,66 +302,11 @@ abstract class Job { } } - function getLastError() { - return $this->error; - } -} - - -/** - * Background job to update links for a given title. - */ -class RefreshLinksJob extends Job { - function __construct( $title, $params = '', $id = 0 ) { - parent::__construct( 'refreshLinks', $title, $params, $id ); + protected function setLastError( $error ) { + $this->error = $error; } - /** - * Run a refreshLinks job - * @return boolean success - */ - function run() { - global $wgParser; - wfProfileIn( __METHOD__ ); - - $linkCache =& LinkCache::singleton(); - $linkCache->clear(); - - if ( is_null( $this->title ) ) { - $this->error = "refreshLinks: Invalid title"; - wfProfileOut( __METHOD__ ); - return false; - } - - $revision = Revision::newFromTitle( $this->title ); - if ( !$revision ) { - $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; - wfProfileOut( __METHOD__ ); - return false; - } - - wfProfileIn( __METHOD__.'-parse' ); - $options = new ParserOptions; - $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); - wfProfileOut( __METHOD__.'-parse' ); - wfProfileIn( __METHOD__.'-update' ); - $update = new LinksUpdate( $this->title, $parserOutput, false ); - $update->doUpdate(); - wfProfileOut( __METHOD__.'-update' ); - wfProfileOut( __METHOD__ ); - return true; - } -} - -class EmaillingJob extends Job { - function __construct($params) { - parent::__construct('sendMail', Title::newMainPage(), $params); - } - - function run() { - userMailer($this->params['to'], $this->params['from'], $this->params['subj'], - $this->params['body'], $this->params['replyto']); + function getLastError() { + return $this->error; } } - -?>