From: River Tarnell Date: Fri, 11 May 2007 07:36:05 +0000 (+0000) Subject: runJobs should have a way to only run certain types of job X-Git-Tag: 1.31.0-rc.0~52954 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=6f53fc41af6d71f67cd5434460afcd8ad07f31bc;hp=f1da5a94100cdc4577109959fdfe5e645a4b915a;p=lhc%2Fweb%2Fwiklou.git runJobs should have a way to only run certain types of job --- diff --git a/includes/JobQueue.php b/includes/JobQueue.php index 3780e4fea1..1e9690252a 100644 --- a/includes/JobQueue.php +++ b/includes/JobQueue.php @@ -38,6 +38,46 @@ abstract class Job { * static function queueLinksJobs( $titles ) {} */ + /** + * Pop a job of a certain type. This tries less hard than pop() to + * actually find a job; it may be adversely affected by concurrent job + * runners. + */ + static function pop_type($type) { + wfProfilein( __METHOD__ ); + + $dbw = wfGetDB( DB_MASTER ); + + + $row = $dbw->selectRow( 'job', '*', array( 'job_cmd' => $type ), __METHOD__, + array( 'LIMIT' => 1 )); + + if ($row === false) { + wfProfileOut( __METHOD__ ); + return false; + } + + /* Ensure we "own" this row */ + $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); + $affected = $dbw->affectedRows(); + + if ($affected == 0) { + wfProfileOut( __METHOD__ ); + return false; + } + + $namespace = $row->job_namespace; + $dbkey = $row->job_title; + $title = Title::makeTitleSafe( $namespace, $dbkey ); + $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); + + $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); + $dbw->immediateCommit(); + + wfProfileOut( __METHOD__ ); + return $job; + } + /** * Pop a job off the front of the queue * @static diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index 91168e5967..6e8e09fa02 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -12,13 +12,28 @@ if ( isset( $options['maxjobs'] ) ) { $maxJobs = 10000; } +$type = false; +if ( isset( $options['type'] ) ) + $type = $options['type']; + $wgTitle = Title::newFromText( 'RunJobs.php' ); $dbw = wfGetDB( DB_MASTER ); $n = 0; -while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) { +$conds = array(); +if ($type !== false) + $conds = array('job_cmd' => $type); + +while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) { $offset=0; - while ( false != ($job = Job::pop($offset)) ) { + for (;;) { + $job = ($type == false) ? + Job::pop($offset, $type) + : Job::pop_type($type); + + if ($job == false) + break; + wfWaitForSlaves( 5 ); print $job->id . " " . $job->toString() . "\n"; $offset=$job->id;