diff --git a/src/Illuminate/Queue/Middleware/RateLimitsJobs.php b/src/Illuminate/Queue/Middleware/RateLimitsJobs.php index 46b512c0e5ef..2ca2428b1aee 100644 --- a/src/Illuminate/Queue/Middleware/RateLimitsJobs.php +++ b/src/Illuminate/Queue/Middleware/RateLimitsJobs.php @@ -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; } @@ -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() + ); } /** @@ -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; } } diff --git a/src/Illuminate/Queue/Middleware/RateLimitsJobsWithRedis.php b/src/Illuminate/Queue/Middleware/RateLimitsJobsWithRedis.php index 0409d5cd9995..eb567fa912be 100644 --- a/src/Illuminate/Queue/Middleware/RateLimitsJobsWithRedis.php +++ b/src/Illuminate/Queue/Middleware/RateLimitsJobsWithRedis.php @@ -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) @@ -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; } }