updated-packages
This commit is contained in:
94
vendor/aws/aws-sdk-php/src/RetryMiddleware.php
vendored
94
vendor/aws/aws-sdk-php/src/RetryMiddleware.php
vendored
@@ -2,16 +2,21 @@
|
||||
namespace Aws;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
use Aws\Retry\RetryHelperTrait;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* @internal Middleware that retries failures.
|
||||
* Middleware that retries failures. V1 implemention that supports 'legacy' mode.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RetryMiddleware
|
||||
{
|
||||
use RetryHelperTrait;
|
||||
|
||||
private static $retryStatusCodes = [
|
||||
500 => true,
|
||||
502 => true,
|
||||
@@ -29,6 +34,9 @@ class RetryMiddleware
|
||||
'RequestThrottled' => true,
|
||||
'BandwidthLimitExceeded' => true,
|
||||
'RequestThrottledException' => true,
|
||||
'TooManyRequestsException' => true,
|
||||
'IDPCommunicationError' => true,
|
||||
'EC2ThrottledException' => true,
|
||||
];
|
||||
|
||||
private $decider;
|
||||
@@ -51,7 +59,7 @@ class RetryMiddleware
|
||||
/**
|
||||
* Creates a default AWS retry decider function.
|
||||
*
|
||||
* The optional $additionalRetryConfig parameter is an associative array
|
||||
* The optional $extraConfig parameter is an associative array
|
||||
* that specifies additional retry conditions on top of the ones specified
|
||||
* by default by the Aws\RetryMiddleware class, with the following keys:
|
||||
*
|
||||
@@ -63,12 +71,12 @@ class RetryMiddleware
|
||||
* these should be valid Curl constants. Optional.
|
||||
*
|
||||
* @param int $maxRetries
|
||||
* @param array $additionalRetryConfig
|
||||
* @param array $extraConfig
|
||||
* @return callable
|
||||
*/
|
||||
public static function createDefaultDecider(
|
||||
$maxRetries = 3,
|
||||
$additionalRetryConfig = []
|
||||
$extraConfig = []
|
||||
) {
|
||||
$retryCurlErrors = [];
|
||||
if (extension_loaded('curl')) {
|
||||
@@ -81,7 +89,7 @@ class RetryMiddleware
|
||||
RequestInterface $request,
|
||||
ResultInterface $result = null,
|
||||
$error = null
|
||||
) use ($maxRetries, $retryCurlErrors, $additionalRetryConfig) {
|
||||
) use ($maxRetries, $retryCurlErrors, $extraConfig) {
|
||||
// Allow command-level options to override this value
|
||||
$maxRetries = null !== $command['@retries'] ?
|
||||
$command['@retries']
|
||||
@@ -91,7 +99,7 @@ class RetryMiddleware
|
||||
$result,
|
||||
$error,
|
||||
$retryCurlErrors,
|
||||
$additionalRetryConfig
|
||||
$extraConfig
|
||||
);
|
||||
|
||||
if ($retries >= $maxRetries) {
|
||||
@@ -112,35 +120,38 @@ class RetryMiddleware
|
||||
$result,
|
||||
$error,
|
||||
$retryCurlErrors,
|
||||
$additionalRetryConfig = []
|
||||
$extraConfig = []
|
||||
) {
|
||||
$errorCodes = self::$retryCodes;
|
||||
if (!empty($additionalRetryConfig['errorCodes'])
|
||||
&& is_array($additionalRetryConfig['errorCodes'])
|
||||
if (!empty($extraConfig['error_codes'])
|
||||
&& is_array($extraConfig['error_codes'])
|
||||
) {
|
||||
foreach($additionalRetryConfig['errorCodes'] as $code) {
|
||||
foreach($extraConfig['error_codes'] as $code) {
|
||||
$errorCodes[$code] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$statusCodes = self::$retryStatusCodes;
|
||||
if (!empty($additionalRetryConfig['statusCodes'])
|
||||
&& is_array($additionalRetryConfig['statusCodes'])
|
||||
if (!empty($extraConfig['status_codes'])
|
||||
&& is_array($extraConfig['status_codes'])
|
||||
) {
|
||||
foreach($additionalRetryConfig['statusCodes'] as $code) {
|
||||
foreach($extraConfig['status_codes'] as $code) {
|
||||
$statusCodes[$code] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($additionalRetryConfig['curlErrors'])
|
||||
&& is_array($additionalRetryConfig['curlErrors'])
|
||||
if (!empty($extraConfig['curl_errors'])
|
||||
&& is_array($extraConfig['curl_errors'])
|
||||
) {
|
||||
foreach($additionalRetryConfig['curlErrors'] as $code) {
|
||||
foreach($extraConfig['curl_errors'] as $code) {
|
||||
$retryCurlErrors[$code] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
if (!isset($result['@metadata']['statusCode'])) {
|
||||
return false;
|
||||
}
|
||||
return isset($statusCodes[$result['@metadata']['statusCode']]);
|
||||
}
|
||||
|
||||
@@ -238,7 +249,7 @@ class RetryMiddleware
|
||||
}
|
||||
if ($value instanceof \Exception || $value instanceof \Throwable) {
|
||||
if (!$decider($retries, $command, $request, null, $value)) {
|
||||
return Promise\rejection_for(
|
||||
return Promise\Create::rejectionFor(
|
||||
$this->bindStatsToReturn($value, $requestStats)
|
||||
);
|
||||
}
|
||||
@@ -263,53 +274,4 @@ class RetryMiddleware
|
||||
|
||||
return $handler($command, $request)->then($g, $g);
|
||||
}
|
||||
|
||||
private function addRetryHeader($request, $retries, $delayBy)
|
||||
{
|
||||
return $request->withHeader('aws-sdk-retry', "{$retries}/{$delayBy}");
|
||||
}
|
||||
|
||||
private function updateStats($retries, $delay, array &$stats)
|
||||
{
|
||||
if (!isset($stats['total_retry_delay'])) {
|
||||
$stats['total_retry_delay'] = 0;
|
||||
}
|
||||
|
||||
$stats['total_retry_delay'] += $delay;
|
||||
$stats['retries_attempted'] = $retries;
|
||||
}
|
||||
|
||||
private function updateHttpStats($value, array &$stats)
|
||||
{
|
||||
if (empty($stats['http'])) {
|
||||
$stats['http'] = [];
|
||||
}
|
||||
|
||||
if ($value instanceof AwsException) {
|
||||
$resultStats = isset($value->getTransferInfo('http')[0])
|
||||
? $value->getTransferInfo('http')[0]
|
||||
: [];
|
||||
$stats['http'] []= $resultStats;
|
||||
} elseif ($value instanceof ResultInterface) {
|
||||
$resultStats = isset($value['@metadata']['transferStats']['http'][0])
|
||||
? $value['@metadata']['transferStats']['http'][0]
|
||||
: [];
|
||||
$stats['http'] []= $resultStats;
|
||||
}
|
||||
}
|
||||
|
||||
private function bindStatsToReturn($return, array $stats)
|
||||
{
|
||||
if ($return instanceof ResultInterface) {
|
||||
if (!isset($return['@metadata'])) {
|
||||
$return['@metadata'] = [];
|
||||
}
|
||||
|
||||
$return['@metadata']['transferStats'] = $stats;
|
||||
} elseif ($return instanceof AwsException) {
|
||||
$return->setTransferInfo($stats);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user