class ThrottlesExceptionsWithRedis extends ThrottlesExceptions

Traits

Properties

protected string|null $key

The developer specified key that the rate limiter should use.

from  ThrottlesExceptions
protected bool $byJob

Indicates whether the throttle key should use the job's UUID.

from  ThrottlesExceptions
protected Closure|int $retryAfterMinutes

The number of minutes to wait before retrying the job after an exception.

from  ThrottlesExceptions
protected ?callable $reportCallback

The callback that determines if the exception should be reported.

from  ThrottlesExceptions
protected ?callable $whenCallback

The callback that determines if rate limiting should apply.

from  ThrottlesExceptions
protected callable[] $deleteWhenCallbacks

The callbacks that determine if the job should be deleted.

from  ThrottlesExceptions
protected callable[] $failWhenCallbacks

The callbacks that determine if the job should be failed.

from  ThrottlesExceptions
protected string $prefix

The prefix of the rate limiter key.

from  ThrottlesExceptions
protected $limiter

The rate limiter instance.

from  ThrottlesExceptions
protected RedisProxy|null $redis

The Redis connection instance.

protected string|null $connectionName

The Redis connection that should be used.

Methods

__construct(int $maxAttempts = 10, int $decaySeconds = 600)

Create a new middleware instance.

mixed
handle(mixed $job, callable $next)

Process the job.

when(callable $callback)

Specify a callback that should determine if rate limiting behavior should apply.

deleteWhen(callable|string $callback)

Add a callback that should determine if the job should be deleted.

failWhen(callable|string $callback)

Add a callback that should determine if the job should be failed.

bool
shouldDelete(Throwable $throwable)

Determine if the job should be deleted for the given exception.

bool
shouldFail(Throwable $throwable)

Determine if the job should be failed for the given exception.

withPrefix(string $prefix)

Set the prefix of the rate limiter key.

backoff(Closure|int $backoff)

Specify the number of minutes a job should be delayed when it is released (before it has reached its max exceptions).

int
getTimeUntilNextRetryAfterException(Throwable $throwable)

Get the number of seconds that should elapse before the job is retried after an exception.

string
getKey(mixed $job)

Get the cache key associated for the rate limiter.

by(string $key)

Set the value that the rate limiter should be keyed by.

byJob()

Indicate that the throttle key should use the job's UUID.

report(callable|null $callback = null)

Report exceptions and optionally specify a callback that determines if the exception should be reported.

int
getTimeUntilNextRetry(string $key)

Get the number of seconds that should elapse before the job is retried.

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

connection(string $name)

Specify the Redis connection that should be used.

Details

__construct(int $maxAttempts = 10, int $decaySeconds = 600)

Create a new middleware instance.

Parameters

int $maxAttempts

the maximum number of attempts allowed before rate limiting applies

int $decaySeconds

the number of seconds until the maximum attempts are reset

at line 31
mixed handle(mixed $job, callable $next)

Process the job.

Parameters

mixed $job
callable $next

Return Value

mixed

in ThrottlesExceptions at line 125
ThrottlesExceptions when(callable $callback)

Specify a callback that should determine if rate limiting behavior should apply.

Parameters

callable $callback

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 135
ThrottlesExceptions deleteWhen(callable|string $callback)

Add a callback that should determine if the job should be deleted.

Parameters

callable|string $callback

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 147
ThrottlesExceptions failWhen(callable|string $callback)

Add a callback that should determine if the job should be failed.

Parameters

callable|string $callback

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 159
protected bool shouldDelete(Throwable $throwable)

Determine if the job should be deleted for the given exception.

Parameters

Throwable $throwable

Return Value

bool

in ThrottlesExceptions at line 173
protected bool shouldFail(Throwable $throwable)

Determine if the job should be failed for the given exception.

Parameters

Throwable $throwable

Return Value

bool

in ThrottlesExceptions at line 187
ThrottlesExceptions withPrefix(string $prefix)

Set the prefix of the rate limiter key.

Parameters

string $prefix

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 197
ThrottlesExceptions backoff(Closure|int $backoff)

Specify the number of minutes a job should be delayed when it is released (before it has reached its max exceptions).

Parameters

Closure|int $backoff

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 207
protected int getTimeUntilNextRetryAfterException(Throwable $throwable)

Get the number of seconds that should elapse before the job is retried after an exception.

Parameters

Throwable $throwable

Return Value

int

in ThrottlesExceptions at line 219
protected string getKey(mixed $job)

Get the cache key associated for the rate limiter.

Parameters

mixed $job

Return Value

string

in ThrottlesExceptions at line 239
ThrottlesExceptions by(string $key)

Set the value that the rate limiter should be keyed by.

Parameters

string $key

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 249
ThrottlesExceptions byJob()

Indicate that the throttle key should use the job's UUID.

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 259
ThrottlesExceptions report(callable|null $callback = null)

Report exceptions and optionally specify a callback that determines if the exception should be reported.

Parameters

callable|null $callback

Return Value

ThrottlesExceptions

in ThrottlesExceptions at line 269
protected int getTimeUntilNextRetry(string $key)

Get the number of seconds that should elapse before the job is retried.

Parameters

string $key

Return Value

int

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

at line 80
ThrottlesExceptionsWithRedis connection(string $name)

Specify the Redis connection that should be used.

Parameters

string $name

Return Value

ThrottlesExceptionsWithRedis