/** @internal */
 public static function _applyRetryConfig($value, array &$args, HandlerList $list)
 {
     if (!$value) {
         return;
     }
     $list->appendSign(Middleware::retry(RetryMiddleware::createDefaultDecider($value), function ($retries) {
         return $retries ? 50 * (int) pow(2, $retries - 1) / 1000 : 0;
     }), 'retry');
 }
 /** @internal */
 public static function _applyRetryConfig($value, array &$args, HandlerList $list)
 {
     if (!$value) {
         return;
     }
     $list->appendSign(Middleware::retry(RetryMiddleware::createDefaultDecider($value), function ($retries) {
         return $retries ? RetryMiddleware::exponentialDelay($retries) / 2 : 0;
     }, isset($args['stats']['retries']) ? (bool) $args['stats']['retries'] : false), 'retry');
 }
Esempio n. 3
0
 /** @internal */
 public static function _applyRetryConfig($value, $_, HandlerList $list)
 {
     if (!$value) {
         return;
     }
     $decider = RetryMiddleware::createDefaultDecider($value);
     $decider = function ($retries, $command, $request, $result, $error) use($decider, $value) {
         $maxRetries = null !== $command['@retries'] ? $command['@retries'] : $value;
         if ($decider($retries, $command, $request, $result, $error)) {
             return true;
         } elseif ($error instanceof AwsException && $retries < $maxRetries) {
             if ($error->getResponse() && $error->getResponse()->getStatusCode() >= 400) {
                 return strpos($error->getResponse()->getBody(), 'Your socket connection to the server') !== false;
             } elseif ($error->getPrevious() instanceof RequestException) {
                 // All commands except CompleteMultipartUpload are
                 // idempotent and may be retried without worry if a
                 // networking error has occurred.
                 return $command->getName() !== 'CompleteMultipartUpload';
             }
         }
         return false;
     };
     $delay = [RetryMiddleware::class, 'exponentialDelay'];
     $list->appendSign(Middleware::retry($decider, $delay), 'retry');
 }
 /** @internal */
 public static function _applyRetryConfig($value, $_, HandlerList $list)
 {
     if (!$value) {
         return;
     }
     $decider = RetryMiddleware::createDefaultDecider($value);
     $decider = function ($retries, $request, $result, $error) use($decider) {
         if ($decider($retries, $request, $result, $error)) {
             return true;
         } elseif ($error instanceof AwsException) {
             return $error->getResponse() && strpos($error->getResponse()->getBody(), 'Your socket connection to the server') !== false;
         }
         return false;
     };
     $delay = [RetryMiddleware::class, 'exponentialDelay'];
     $list->appendSign(Middleware::retry($decider, $delay), 'retry');
 }
Esempio n. 5
0
 public static function _apply_retries($value, array &$args, HandlerList $list)
 {
     if ($value) {
         $decider = RetryMiddleware::createDefaultDecider($value);
         $list->appendSign(Middleware::retry($decider), 'retry');
     }
 }
 /**
  * Middleware wrapper function that retries requests based on the boolean
  * result of invoking the provided "decider" function.
  *
  * If no delay function is provided, a simple implementation of exponential
  * backoff will be utilized.
  *
  * @param callable $decider Function that accepts the number of retries,
  *                          a request, [result], and [exception] and
  *                          returns true if the command is to be retried.
  * @param callable $delay   Function that accepts the number of retries and
  *                          returns the number of milliseconds to delay.
  * @param bool $stats       Whether to collect statistics on retries and the
  *                          associated delay.
  *
  * @return callable
  */
 public static function retry(callable $decider = null, callable $delay = null, $stats = false)
 {
     $decider = $decider ?: RetryMiddleware::createDefaultDecider();
     $delay = $delay ?: [RetryMiddleware::class, 'exponentialDelay'];
     return function (callable $handler) use($decider, $delay, $stats) {
         return new RetryMiddleware($decider, $delay, $handler, $stats);
     };
 }