From 9399d52dc674de7da8011b7a6cd3390290df77f0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 28 Mar 2013 21:00:42 -0700 Subject: [PATCH] [JobQueue] Added more isQueueDeprioritized() checks to avoid refreshLinks spam. Change-Id: I29cb22ed471f129efba2bb7b0743c700456f0f4d --- includes/job/JobQueueGroup.php | 14 +++++++++++++- maintenance/runJobs.php | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/job/JobQueueGroup.php b/includes/job/JobQueueGroup.php index 351c71a370..85f99b7167 100644 --- a/includes/job/JobQueueGroup.php +++ b/includes/job/JobQueueGroup.php @@ -40,6 +40,7 @@ class JobQueueGroup { const TYPE_ANY = 2; // integer; any job const USE_CACHE = 1; // integer; use process or persistent cache + const USE_PRIORITY = 2; // integer; respect deprioritization const PROC_CACHE_TTL = 15; // integer; seconds @@ -146,6 +147,9 @@ class JobQueueGroup { */ public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0 ) { if ( is_string( $qtype ) ) { // specific job type + if ( ( $flags & self::USE_PRIORITY ) && $this->isQueueDeprioritized( $qtype ) ) { + return false; // back off + } $job = $this->get( $qtype )->pop(); if ( !$job ) { JobQueueAggregator::singleton()->notifyQueueEmpty( $this->wiki, $qtype ); @@ -167,6 +171,9 @@ class JobQueueGroup { shuffle( $types ); // avoid starvation foreach ( $types as $type ) { // for each queue... + if ( ( $flags & self::USE_PRIORITY ) && $this->isQueueDeprioritized( $type ) ) { + continue; // back off + } $job = $this->get( $type )->pop(); if ( $job ) { // found return $job; @@ -264,10 +271,15 @@ class JobQueueGroup { * @return bool */ public function isQueueDeprioritized( $type ) { + if ( $this->cache->has( 'isDeprioritized', $type, 5 ) ) { + return $this->cache->get( 'isDeprioritized', $type ); + } if ( $type === 'refreshLinks2' ) { // Don't keep converting refreshLinks2 => refreshLinks jobs if the // later jobs have not been done yet. This helps throttle queue spam. - return !$this->get( 'refreshLinks' )->isEmpty(); + $deprioritized = !$this->get( 'refreshLinks' )->isEmpty(); + $this->cache->set( 'isDeprioritized', $type, $deprioritized ); + return $deprioritized; } return false; } diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index b1be714c14..abe83352a0 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -82,10 +82,11 @@ class RunJobs extends Maintenance { $this->runJobsLog( "Executed $count periodic queue task(s)." ); } + $flags = JobQueueGroup::USE_CACHE | JobQueueGroup::USE_PRIORITY; $lastTime = time(); do { $job = ( $type === false ) - ? $group->pop( JobQueueGroup::TYPE_DEFAULT, JobQueueGroup::USE_CACHE ) + ? $group->pop( JobQueueGroup::TYPE_DEFAULT, $flags ) : $group->pop( $type ); // job from a single queue if ( $job ) { // found a job ++$jobsRun; -- 2.20.1