Skip to content

Commit

Permalink
inform clients of retry attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
suadhuskic authored and huskicsuad committed Oct 15, 2019
1 parent 8278b83 commit 0cec4d6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private function executeRequestWithRetries($opts, $absUrl)
if ($this->shouldRetry($errno, $rcode, $rheaders, $numRetries)) {
$numRetries += 1;
$sleepSeconds = $this->sleepTime($numRetries, $rheaders);
Stripe::informOfRetry($numRetries);
usleep(intval($sleepSeconds * 1000000));
} else {
break;
Expand Down
31 changes: 31 additions & 0 deletions lib/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Stripe
// @var float Initial delay between retries, in seconds
private static $initialNetworkRetryDelay = 0.5;

// @var callable|null A callback to inform when we attempt a retry.
public static $retryInformCallback;

const VERSION = '7.3.1';

/**
Expand Down Expand Up @@ -273,4 +276,32 @@ public static function setEnableTelemetry($enableTelemetry)
{
self::$enableTelemetry = $enableTelemetry;
}

/**
* @return callable|null
*/
public static function getRetryInformCallback()
{
return self::$retryInformCallback;
}

/**
* @param callable $retryInformCallback
*/
public static function setRetryInformCallback(callable $retryInformCallback)
{
self::$retryInformCallback = $retryInformCallback;
}

/**
* If a client registered a callback to inform them of retries, call to inform.
* @param int $retryAttempt
*/
public static function informOfRetry($retryAttempt)
{
if (!is_callable(self::$retryInformCallback)) {
return;
}
call_user_func_array(self::$retryInformCallback, [$retryAttempt]);
}
}

0 comments on commit 0cec4d6

Please sign in to comment.