@@ -31,7 +31,7 @@ public function __construct()
3131
3232 protected function retryDelay (int $ retryCount , Backoff $ backoff )
3333 {
34- return $ backoff ->getBackoffSlotMillis ()*( 1 << min ($ retryCount , $ backoff ->getBackoffCeiling ()));
34+ return $ backoff ->getBackoffSlotMillis () * ( 1 << min ($ retryCount , $ backoff ->getBackoffCeiling ()));
3535 }
3636
3737 /**
@@ -72,21 +72,22 @@ public function withParams(?RetryParams $params): Retry
7272 * @throws NonRetryableException
7373 * @throws RetryableException
7474 */
75- public function retry (Closure $ closure , bool $ idempotent ){
75+ public function retry (Closure $ closure , bool $ idempotent )
76+ {
7677 $ startTime = microtime (true );
7778 $ retryCount = 0 ;
7879 $ lastException = null ;
79- while (microtime (true ) < $ startTime+ $ this ->timeoutMs / 1000 ){
80+ while (microtime (true ) < $ startTime + $ this ->timeoutMs / 1000 ) {
8081 try {
8182 return $ closure ();
82- } catch (RetryableException $ e ){
83- if (! isset (self ::$ idempotentOnly [get_class ($ e )])) {
83+ } catch (RetryableException $ e ) {
84+ if (isset (self ::$ idempotentOnly [get_class ($ e )]) && $ idempotent ) {
8485 throw $ e ;
8586 }
8687 $ retryCount ++;
87- $ this ->retryDelay ($ retryCount ,$ this ->backoffType ($ e ));
88+ $ this ->retryDelay ($ retryCount , $ this ->backoffType ($ e ));
8889 $ lastException = $ e ;
89- } catch (Exception $ e ){
90+ } catch (Exception $ e ) {
9091 throw $ e ;
9192 }
9293 }
@@ -99,23 +100,24 @@ public function retry(Closure $closure, bool $idempotent){
99100 */
100101 protected function backoffType (RetryableException $ e ): Backoff
101102 {
102- if ($ e instanceof AbortedException){
103- return $ this ->fastBackOff ;
104- } elseif ($ e instanceof BadSessionException) {
105- return $ this ->fastBackOff ;
106- } elseif ($ e instanceof SessionBusyException) {
107- return $ this ->fastBackOff ;
108- } elseif ($ e instanceof UndeterminedException) {
109- return $ this ->fastBackOff ;
110- } elseif ($ e instanceof UnavailableException) {
111- return $ this ->fastBackOff ;
112- } elseif ($ e instanceof UndeterminedException) {
113- return $ this ->fastBackOff ;
114- } elseif ($ e instanceof DeadlineExceededException){
115- return $ this ->fastBackOff ;
116- } else {
117- return $ this ->slowBackOff ;
118- }
103+ return $ this ->fastBackOff ;
104+ // if ($e instanceof AbortedException) {
105+ // return $this->fastBackOff;
106+ // } elseif ($e instanceof BadSessionException) {
107+ // return $this->fastBackOff;
108+ // } elseif ($e instanceof SessionBusyException) {
109+ // return $this->fastBackOff;
110+ // } elseif ($e instanceof UndeterminedException) {
111+ // return $this->fastBackOff;
112+ // } elseif ($e instanceof UnavailableException) {
113+ // return $this->fastBackOff;
114+ // } elseif ($e instanceof UndeterminedException) {
115+ // return $this->fastBackOff;
116+ // } elseif ($e instanceof DeadlineExceededException) {
117+ // return $this->fastBackOff;
118+ // } else {
119+ // return $this->slowBackOff;
120+ // }
119121 }
120122
121123 private static $ idempotentOnly = [
0 commit comments