Scalr\Service\OpenStack\Client\RestClient::tryCall PHP Method

tryCall() protected method

Tries to send request on several attempts.
protected tryCall ( Scalr\System\Http\Client\Request $httpRequest, integer $attempts = 1, integer $interval = 200 ) : http\Client\Response
$httpRequest Scalr\System\Http\Client\Request
$attempts integer Attempts count.
$interval integer An sleep interval between an attempts in microseconds.
return http\Client\Response Returns http Response if success.
    protected function tryCall($httpRequest, $attempts = 1, $interval = 200)
    {
        try {
            $response = \Scalr::getContainer()->http->sendRequest($httpRequest);
            if (is_callable($this->callback)) {
                call_user_func($this->callback, $httpRequest, $response);
            }
        } catch (\http\Exception $e) {
            if (--$attempts > 0) {
                usleep($interval);
                $response = $this->tryCall($httpRequest, $attempts, $interval * 2);
            } else {
                throw new RestClientException(sprintf('Cannot establish connection with OpenStack server (%s). (%s).', $httpRequest->getRequestUrl(), isset($e->innerException) ? preg_replace('/(\\(.*\\))/', '', $e->innerException->getMessage()) : $e->getMessage()));
            }
        }
        return $response;
    }