Skip to content

Commit

Permalink
formatting... add padding to release
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 15, 2020
1 parent 49c8b3d commit ae00294
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
42 changes: 21 additions & 21 deletions src/Illuminate/Queue/Middleware/RateLimitsJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class RateLimitsJobs
protected $limiterName;

/**
* Create a new rate limiter middleware instance.
* Create a new middleware instance.
*
* @param string $limiterName
*
* @return void
*/
public function __construct($limiterName)
{
$this->limiter = Container::getInstance()->make(RateLimiter::class);

$this->limiterName = $limiterName;
}

Expand All @@ -45,27 +45,27 @@ public function __construct($limiterName)
*/
public function handle($job, $next)
{
if (! is_null($limiter = $this->limiter->limiter($this->limiterName))) {
$limiterResponse = call_user_func($limiter, $job);
if (is_null($limiter = $this->limiter->limiter($this->limiterName))) {
return $next($job);
}

if ($limiterResponse instanceof Unlimited) {
return $next($job);
}
$limiterResponse = call_user_func($limiter, $job);

return $this->handleJob(
$job,
$next,
collect(Arr::wrap($limiterResponse))->map(function ($limit) {
return (object) [
'key' => md5($this->limiterName.$limit->key),
'maxAttempts' => $limit->maxAttempts,
'decayMinutes' => $limit->decayMinutes,
];
})->all()
);
} else {
if ($limiterResponse instanceof Unlimited) {
return $next($job);
}

return $this->handleJob(
$job,
$next,
collect(Arr::wrap($limiterResponse))->map(function ($limit) {
return (object) [
'key' => md5($this->limiterName.$limit->key),
'maxAttempts' => $limit->maxAttempts,
'decayMinutes' => $limit->decayMinutes,
];
})->all()
);
}

/**
Expand All @@ -90,13 +90,13 @@ protected function handleJob($job, $next, array $limits)
}

/**
* Get the number of seconds until the next retry.
* Get the number of seconds that should elapse before the job is retried.
*
* @param string $key
* @return int
*/
protected function getTimeUntilNextRetry($key)
{
return $this->limiter->availableIn($key);
return $this->limiter->availableIn($key) + 3;
}
}
7 changes: 3 additions & 4 deletions src/Illuminate/Queue/Middleware/RateLimitsJobsWithRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class RateLimitsJobsWithRedis extends RateLimitsJobs
public $decaysAt = [];

/**
* Create a new rate limiter middleware instance.
* Create a new middleware instance.
*
* @param string $limiterName
*
* @return void
*/
public function __construct($limiterName)
Expand Down Expand Up @@ -78,13 +77,13 @@ protected function tooManyAttempts($key, $maxAttempts, $decayMinutes)
}

/**
* Get the number of seconds until the lock is released.
* Get the number of seconds that should elapse before the job is retried.
*
* @param string $key
* @return int
*/
protected function getTimeUntilNextRetry($key)
{
return $this->decaysAt[$key] - $this->currentTime();
return ($this->decaysAt[$key] - $this->currentTime()) + 3;
}
}

0 comments on commit ae00294

Please sign in to comment.