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
*/
$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;
}
/**
'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 ) );
"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).
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