Skip to content

Commit

Permalink
use response.pause
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Sep 14, 2020
1 parent 4f257cb commit 3a5f3f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Expand Up @@ -1653,7 +1653,8 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->info('A list of HTTP status code that triggers a retry')
->defaultValue([423, 425, 429, 500, 502, 503, 504, 507, 510])
->end() ->integerNode('max_retries')->defaultValue(3)->min(0)->end()
->end()
->integerNode('max_retries')->defaultValue(3)->min(0)->end()
->integerNode('delay')->defaultValue(1000)->min(0)->info('Time in ms to delay (or the initial value when multiplier is used)')->end()
->floatNode('multiplier')->defaultValue(2)->min(1)->info('If greater than 1, delay will grow exponentially for each retry: this delay = (delay * (multiple ^ retries))')->end()
->integerNode('max_delay')->defaultValue(0)->min(0)->info('Max time in ms that a retry should ever be delayed (0 = infinite)')->end()
Expand Down
Expand Up @@ -1994,7 +1994,7 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
$container->removeDefinition(HttpClient::class);
}

$applyRetry = static function(array $retryOptions, string $name) use ($container) {
$applyRetry = static function (array $retryOptions, string $name) use ($container) {
if (!($retryOptions['enabled'] ?? false)) {
return;
}
Expand All @@ -2020,7 +2020,7 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
->setArguments([
new Reference($name.'.retry.inner'),
$retryReferences,
new Reference('logger')
new Reference('logger'),
])
->addTag('monolog.logger', ['channel' => 'http_client']);
};
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/HttpClient/RetryHttpClient.php
Expand Up @@ -66,7 +66,7 @@ public function request(string $method, string $url, array $options = []): Respo
++$this->retryCount;

$context->setInfo('retry', $this->retryCount);
$context->getResponse()->cancel();
$response->cancel();

$delay = $this->strategy->getWaitingTime($this->retryCount, $response, $exception);

Expand All @@ -75,11 +75,9 @@ public function request(string $method, string $url, array $options = []): Respo
'delay' => $delay,
'error' => ($exception ? $exception->getMessage() : 'StatusCode: '.$response->getStatusCode()),
]);
if ($delay > 0) {
usleep($delay * 1000);
}

$context->replaceRequest($method, $url, $options);
$context->pause($delay / 1000);
});
}
}

0 comments on commit 3a5f3f5

Please sign in to comment.