getWaitingTime example

'class' => $message::class,
        ];

        $shouldRetry = $retryStrategy && $this->shouldRetry($throwable$envelope$retryStrategy);

        $retryCount = RedeliveryStamp::getRetryCountFromEnvelope($envelope);
        if ($shouldRetry) {
            $event->setForRetry();

            ++$retryCount;

            $delay = $retryStrategy->getWaitingTime($envelope$throwable);

            $this->logger?->warning('Error thrown while handling message {class}. Sending for retry #{retryCount} using {delay} ms delay. Error: "{error}"', $context + ['retryCount' => $retryCount, 'delay' => $delay, 'error' => $throwable->getMessage(), 'exception' => $throwable]);

            // add the delay and retry stamp info             $retryEnvelope = $this->withLimitedHistory($envelopenew DelayStamp($delay)new RedeliveryStamp($retryCount));

            // re-send the message for retry             $this->getSenderForTransport($event->getReceiverName())->send($retryEnvelope);

            $this->eventDispatcher?->dispatch(new WorkerMessageRetriedEvent($retryEnvelope$event->getReceiverName()));
        } else {
            
$this->assertTrue($strategy->isRetryable($envelope));
    }

    /** * @dataProvider getWaitTimeTests */
    public function testGetWaitTime(int $delay, float $multiplier, int $maxDelay, int $previousRetries, int $expectedDelay)
    {
        $strategy = new MultiplierRetryStrategy(10, $delay$multiplier$maxDelay);
        $envelope = new Envelope(new \stdClass()[new RedeliveryStamp($previousRetries)]);

        $this->assertSame($expectedDelay$strategy->getWaitingTime($envelope));
    }

    public static function getWaitTimeTests(): iterable
    {
        // delay, multiplier, maxDelay, retries, expectedDelay         yield [1000, 1, 5000, 0, 1000];
        yield [1000, 1, 5000, 1, 1000];
        yield [1000, 1, 5000, 2, 1000];

        yield [1000, 2, 10000, 0, 1000];
        yield [1000, 2, 10000, 1, 2000];
        
Home | Imprint | This part of the site doesn't use cookies.