Skip to content

Commit 3cd579a

Browse files
committed
Add jitter to RetryBackof
1 parent 248c579 commit 3cd579a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,8 @@ private function addHttpClientRetrySection()
16411641
->addDefaultsIfNotSet()
16421642
->beforeNormalization()
16431643
->always(function ($v) {
1644-
if (isset($v['backoff_service']) && (isset($v['delay']) || isset($v['multiplier']) || isset($v['max_delay']))) {
1645-
throw new \InvalidArgumentException('The "backoff_service" option cannot be used along with the "delay", "multiplier" or "max_delay" options.');
1644+
if (isset($v['backoff_service']) && (isset($v['delay']) || isset($v['multiplier']) || isset($v['max_delay']) || isset($v['jitter']))) {
1645+
throw new \InvalidArgumentException('The "backoff_service" option cannot be used along with the "delay", "multiplier", "max_delay" or "jitter" options.');
16461646
}
16471647
if (isset($v['decider_service']) && (isset($v['http_codes']))) {
16481648
throw new \InvalidArgumentException('The "decider_service" option cannot be used along with the "http_codes" options.');
@@ -1670,6 +1670,7 @@ private function addHttpClientRetrySection()
16701670
->integerNode('delay')->defaultValue(1000)->min(0)->info('Time in ms to delay (or the initial value when multiplier is used)')->end()
16711671
->floatNode('multiplier')->defaultValue(2)->min(1)->info('If greater than 1, delay will grow exponentially for each retry: (delay * (multiple ^ retries))')->end()
16721672
->integerNode('max_delay')->defaultValue(0)->min(0)->info('Max time in ms that a retry should ever be delayed (0 = infinite)')->end()
1673+
->floatNode('jitter')->defaultValue(0.1)->min(0)->max(1)->info('Randomness in percent (between 0 and 1)) to apply to the delay')->end()
16731674
->end()
16741675
;
16751676
}

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,8 @@ private function registerHttpClientRetry(array $retryOptions, string $name, Cont
20752075
$retryDefinition
20762076
->replaceArgument(0, $retryOptions['delay'])
20772077
->replaceArgument(1, $retryOptions['multiplier'])
2078-
->replaceArgument(2, $retryOptions['max_delay']);
2078+
->replaceArgument(2, $retryOptions['max_delay'])
2079+
->replaceArgument(3, $retryOptions['jitter']);
20792080
$container->setDefinition($retryServiceId, $retryDefinition);
20802081

20812082
$backoffReference = new Reference($retryServiceId);

0 commit comments

Comments
 (0)