X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FrunJobs.php;h=b488fe94b22e9c9058fff8f6824cd5625d245356;hb=f856a480b9dc99e62bdeb33df5abe213ac9e0f4f;hp=7c896d2432760ad2ce21609d4227ab84f2118e2e;hpb=2117c11cbc53911f3a34fbd15d706367515ef7e1;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index 7c896d2432..b488fe94b2 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -36,19 +36,19 @@ class RunJobs extends Maintenance { $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true ); $this->addOption( 'type', 'Type of job to run', false, true ); $this->addOption( 'procs', 'Number of processes to use', false, true ); + $this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false ); } public function memoryLimit() { if ( $this->hasOption( 'memory-limit' ) ) { return parent::memoryLimit(); } + // Don't eat all memory on the machine if we get a bad job. return "150M"; } public function execute() { - global $wgTitle; - if ( wfReadOnly() ) { $this->error( "Unable to run jobs; the wiki is in read-only mode.", 1 ); // die } @@ -68,8 +68,8 @@ class RunJobs extends Maintenance { $type = $this->getOption( 'type', false ); $maxJobs = $this->getOption( 'maxjobs', false ); $maxTime = $this->getOption( 'maxtime', false ); + $noThrottle = $this->hasOption( 'nothrottle' ); $startTime = time(); - $wgTitle = Title::newFromText( 'RunJobs.php' ); $group = JobQueueGroup::singleton(); // Handle any required periodic queue maintenance @@ -80,16 +80,20 @@ class RunJobs extends Maintenance { $backoffs = $this->loadBackoffs(); // map of (type => UNIX expiry) $startingBackoffs = $backoffs; // avoid unnecessary writes - $backoffExpireFunc = function( $t ) { return $t > time(); }; + $backoffExpireFunc = function ( $t ) { + return $t > time(); + }; $jobsRun = 0; // counter $flags = JobQueueGroup::USE_CACHE; $lastTime = time(); // time since last slave check do { + $backoffs = array_filter( $backoffs, $backoffExpireFunc ); + $blacklist = $noThrottle ? array() : array_keys( $backoffs ); if ( $type === false ) { - $backoffs = array_filter( $backoffs, $backoffExpireFunc ); - $blacklist = array_keys( $backoffs ); $job = $group->pop( JobQueueGroup::TYPE_DEFAULT, $flags, $blacklist ); + } elseif ( in_array( $type, $blacklist ) ) { + $job = false; // requested queue in backoff state } else { $job = $group->pop( $type ); // job from a single queue } @@ -98,7 +102,7 @@ class RunJobs extends Maintenance { $this->runJobsLog( $job->toString() . " STARTING" ); // Set timer to stop the job if too much CPU time is used - set_time_limit( $maxTime ?: 0 ); + set_time_limit( $maxTime ? : 0 ); // Run the job... wfProfileIn( __METHOD__ . '-' . get_class( $job ) ); $t = microtime( true ); @@ -106,6 +110,7 @@ class RunJobs extends Maintenance { $status = $job->run(); $error = $job->getLastError(); } catch ( MWException $e ) { + MWExceptionHandler::rollbackMasterChangesAndLog( $e ); $status = false; $error = get_class( $e ) . ': ' . $e->getMessage(); $e->report(); // write error to STDERR and the log @@ -165,7 +170,7 @@ class RunJobs extends Maintenance { /** * @param Job $job - * @return integer Seconds for this runner to avoid doing more jobs of this type + * @return int Seconds for this runner to avoid doing more jobs of this type * @see $wgJobBackoffThrottling */ private function getBackoffTimeToWait( Job $job ) { @@ -205,7 +210,7 @@ class RunJobs extends Maintenance { $content = stream_get_contents( $handle ); flock( $handle, LOCK_UN ); fclose( $handle ); - $backoffs = json_decode( $content, true ) ?: array(); + $backoffs = json_decode( $content, true ) ? : array(); } return $backoffs; @@ -223,7 +228,7 @@ class RunJobs extends Maintenance { $handle = fopen( $file, 'wb+' ); flock( $handle, LOCK_EX ); $content = stream_get_contents( $handle ); - $cBackoffs = json_decode( $content, true ) ?: array(); + $cBackoffs = json_decode( $content, true ) ? : array(); foreach ( $backoffs as $type => $timestamp ) { $cBackoffs[$type] = isset( $cBackoffs[$type] ) ? $cBackoffs[$type] : 0; $cBackoffs[$type] = max( $cBackoffs[$type], $backoffs[$type] ); @@ -259,7 +264,7 @@ class RunJobs extends Maintenance { /** * Log the job message - * @param $msg String The message to log + * @param string $msg The message to log */ private function runJobsLog( $msg ) { $this->output( wfTimestamp( TS_DB ) . " $msg\n" );