Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Queue\Middleware;
4
 
5
use Illuminate\Container\Container;
6
use Illuminate\Contracts\Redis\Factory as Redis;
7
use Illuminate\Redis\Limiters\DurationLimiter;
8
use Illuminate\Support\InteractsWithTime;
9
use Throwable;
10
 
11
class ThrottlesExceptionsWithRedis extends ThrottlesExceptions
12
{
13
    use InteractsWithTime;
14
 
15
    /**
16
     * The Redis factory implementation.
17
     *
18
     * @var \Illuminate\Contracts\Redis\Factory
19
     */
20
    protected $redis;
21
 
22
    /**
23
     * The rate limiter instance.
24
     *
25
     * @var \Illuminate\Redis\Limiters\DurationLimiter
26
     */
27
    protected $limiter;
28
 
29
    /**
30
     * Process the job.
31
     *
32
     * @param  mixed  $job
33
     * @param  callable  $next
34
     * @return mixed
35
     */
36
    public function handle($job, $next)
37
    {
38
        $this->redis = Container::getInstance()->make(Redis::class);
39
 
40
        $this->limiter = new DurationLimiter(
41
            $this->redis, $this->getKey($job), $this->maxAttempts, $this->decayMinutes * 60
42
        );
43
 
44
        if ($this->limiter->tooManyAttempts()) {
45
            return $job->release($this->limiter->decaysAt - $this->currentTime());
46
        }
47
 
48
        try {
49
            $next($job);
50
 
51
            $this->limiter->clear();
52
        } catch (Throwable $throwable) {
53
            if ($this->whenCallback && ! call_user_func($this->whenCallback, $throwable)) {
54
                throw $throwable;
55
            }
56
 
57
            $this->limiter->acquire();
58
 
59
            return $job->release($this->retryAfterMinutes * 60);
60
        }
61
    }
62
}