From 1f5f6a1b3dc38ddf04e273b8c359971de6e3c124 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 19 Feb 2013 17:05:28 -0800 Subject: [PATCH] [JobQueue] Made the maximum number of job attempts configurable. Change-Id: I3aaab748913af68f4a676855c5c4f825706f7be7 --- includes/job/JobQueue.php | 4 ++-- includes/job/JobQueueDB.php | 4 ++-- includes/job/JobQueueRedis.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 67fe180e01..f02ed98a83 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -33,11 +33,10 @@ abstract class JobQueue { protected $type; // string; job type protected $order; // string; job priority for pop() protected $claimTTL; // integer; seconds + protected $maxTries; // integer; maximum number of times to try a job const QoS_Atomic = 1; // integer; "all-or-nothing" job insertions - const MAX_ATTEMPTS = 3; // integer; number of times to try a job - /** * @param $params array */ @@ -46,6 +45,7 @@ abstract class JobQueue { $this->type = $params['type']; $this->order = isset( $params['order'] ) ? $params['order'] : 'random'; $this->claimTTL = isset( $params['claimTTL'] ) ? $params['claimTTL'] : 0; + $this->maxTries = isset( $params['maxTries'] ) ? $params['maxTries'] : 3; } /** diff --git a/includes/job/JobQueueDB.php b/includes/job/JobQueueDB.php index f583c52ad3..fd64895047 100644 --- a/includes/job/JobQueueDB.php +++ b/includes/job/JobQueueDB.php @@ -423,7 +423,7 @@ class JobQueueDB extends JobQueue { 'job_cmd' => $this->type, "job_token != {$dbw->addQuotes( '' )}", // was acquired "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale - "job_attempts < {$dbw->addQuotes( self::MAX_ATTEMPTS )}" ), // retries left + "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ), // retries left __METHOD__ ); $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) ); @@ -453,7 +453,7 @@ class JobQueueDB extends JobQueue { "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale ); if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times... - $conds[] = "job_attempts >= {$dbw->addQuotes( self::MAX_ATTEMPTS )}"; + $conds[] = "job_attempts >= {$dbw->addQuotes( $this->maxTries )}"; } // Get the IDs of jobs that are considered stale and should be removed. Selecting // the IDs first means that the UPDATE can be done by primary key (less deadlocks). diff --git a/includes/job/JobQueueRedis.php b/includes/job/JobQueueRedis.php index 07a7410dda..2ce47bb327 100644 --- a/includes/job/JobQueueRedis.php +++ b/includes/job/JobQueueRedis.php @@ -372,7 +372,7 @@ class JobQueueRedis extends JobQueue { if ( $ctime < $claimCutoff ) { // Get the number of failed attempts $attempts = isset( $info['attempts'] ) ? $info['attempts'] : 0; - if ( $attempts < self::MAX_ATTEMPTS ) { + if ( $attempts < $this->maxTries ) { $uidsPush[] = $uid; // retry it } elseif ( $ctime < $pruneCutoff ) { $uidsRemove[] = $uid; // just remove it -- 2.20.1