Skip to content

Commit

Permalink
Added resetInterval method
Browse files Browse the repository at this point in the history
  • Loading branch information
vkartaviy committed May 6, 2015
1 parent 93d49ae commit 517bf3d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Retry/BackOff/ExponentialBackOffContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@

class ExponentialBackOffContext implements BackOffContextInterface
{
private $interval;
private $seed;
private $multiplier;
private $maxInterval;
private $max;

private $interval;

public function __construct($interval, $multiplier, $maxInterval)
public function __construct($seed, $multiplier, $max)
{
$this->interval = max(1, (int) $interval);
$this->multiplier = max(1, (float) $multiplier);
$this->maxInterval = max(1, (int) $maxInterval);
$this->seed = max(1, (int) $seed);
$this->multiplier = max(1, (float) $multiplier);
$this->max = max(1, (int) $max);

$this->interval = $this->seed;
}

public function getIntervalAndIncrement()
{
$interval = $this->interval;

if ($interval > $this->maxInterval) {
$interval = $this->maxInterval;
if ($interval > $this->max) {
$interval = $this->max;
} else {
$this->interval = $this->getNextInterval();
}
Expand All @@ -33,6 +37,11 @@ public function getInterval()
return $this->interval;
}

public function resetInterval()
{
$this->interval = $this->seed;
}

public function getNextInterval()
{
return $this->interval * $this->multiplier;
Expand Down

0 comments on commit 517bf3d

Please sign in to comment.