Final Class Yiisoft\Queue\Middleware\FailureHandling\Implementation\ExponentialDelayMiddleware
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resends failures with exponentially increasing adapter-supported delay.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| META_KEY_ATTEMPTS | 'failure-strategy-exponential-delay-attempts' | Yiisoft\ |
|
| META_KEY_DELAY | 'failure-strategy-exponential-delay-delay' | Yiisoft\ |
Method Details
| public mixed __construct ( string $id, integer $maxAttempts, float $delayInitial, float $delayMaximum, float $exponent, ?\ | ||
| $id | string | |
| $maxAttempts | integer | |
| $delayInitial | float | |
| $delayMaximum | float | |
| $exponent | float | |
| $queue | ?\ |
|
| $producerProvider | ?\ |
|
public function __construct(
private readonly string $id,
private readonly int $maxAttempts,
private readonly float $delayInitial,
private readonly float $delayMaximum,
private readonly float $exponent,
private readonly ?QueueProducerInterface $queue = null,
private readonly ?QueueProducerProviderInterface $producerProvider = null,
) {
if ($maxAttempts <= 0) {
throw new InvalidArgumentException("maxAttempts parameter must be a positive integer, $this->maxAttempts given.");
}
if ($delayInitial <= 0) {
throw new InvalidArgumentException("delayInitial parameter must be a positive float, $this->delayInitial given.");
}
if ($delayMaximum < $delayInitial) {
throw new InvalidArgumentException("delayMaximum parameter must not be less then delayInitial, $this->delayMaximum given.");
}
if ($exponent <= 0) {
throw new InvalidArgumentException("exponent parameter must not be zero or less, $this->exponent given.");
}
}
public function processFailure(FailureHandlingRequest $request, FailureHandlerInterface $handler): FailureHandlingRequest
{
$message = $request->getMessage();
if (!$this->suites($message)) {
return $handler->handleFailure($request);
}
$failure = new FailureEnvelope($message, $this->createNewMeta($message));
$result = $this->producer($request)->push(new DelayEnvelope($failure, $this->getDelay($failure)));
return $request->withMessage($result);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.