X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FJobQueue.php;h=afa757d752ed84f34e1ee6fe777c4edd6dc6059c;hb=7efc871cba8dc24aff2cd13d3ad4c8a20902bad7;hp=ba10b285161ee02555369ec130fef0cb510352a0;hpb=b8cd62a85828bbba1c0b00ca3b9e5677caa849bd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/JobQueue.php b/includes/JobQueue.php index ba10b28516..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,38 +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': - return; - case 'html_cache_update': # BC - return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id ); - case 'sendMail': - return new EmaillingJob( $params ); - case 'enotifNotify': - return new EnotifNotifyJob( $title, $params ); - } - // OK, check if this is a custom job - global $wgCustomJobs; - wfLoadAllExtensions(); // This may be for an extension - - if( isset($wgCustomJobs[$command]) ) { - $class = $wgCustomJobs[$command]; - return new $class($title, $params, $id); - } else { - 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 ) { @@ -220,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(); } @@ -295,81 +302,11 @@ abstract class Job { } } - function getLastError() { - return $this->error; + protected function setLastError( $error ) { + $this->error = $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 ); - } - - /** - * 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']); - } -} - -class EnotifNotifyJob extends Job { - function __construct($title, $params) { - parent::__construct('enotifNotify', $title, $params); - } - - function run() { - $enotif = new EmailNotification(); - $enotif->actuallyNotifyOnPageChange( User::newFromName($this->params['editor'], false), - $this->title, $this->params['timestamp'], - $this->params['summary'], $this->params['minorEdit'], - $this->params['oldid']); + function getLastError() { + return $this->error; } } - - -?>