@@ -31,7 +31,7 @@ public function __construct()
31
31
32
32
protected function retryDelay (int $ retryCount , Backoff $ backoff )
33
33
{
34
- return $ backoff ->getBackoffSlotMillis ()*( 1 << min ($ retryCount , $ backoff ->getBackoffCeiling ()));
34
+ return $ backoff ->getBackoffSlotMillis () * ( 1 << min ($ retryCount , $ backoff ->getBackoffCeiling ()));
35
35
}
36
36
37
37
/**
@@ -72,21 +72,22 @@ public function withParams(?RetryParams $params): Retry
72
72
* @throws NonRetryableException
73
73
* @throws RetryableException
74
74
*/
75
- public function retry (Closure $ closure , bool $ idempotent ){
75
+ public function retry (Closure $ closure , bool $ idempotent )
76
+ {
76
77
$ startTime = microtime (true );
77
78
$ retryCount = 0 ;
78
79
$ lastException = null ;
79
- while (microtime (true ) < $ startTime+ $ this ->timeoutMs / 1000 ){
80
+ while (microtime (true ) < $ startTime + $ this ->timeoutMs / 1000 ) {
80
81
try {
81
82
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 ) {
84
85
throw $ e ;
85
86
}
86
87
$ retryCount ++;
87
- $ this ->retryDelay ($ retryCount ,$ this ->backoffType ($ e ));
88
+ $ this ->retryDelay ($ retryCount , $ this ->backoffType ($ e ));
88
89
$ lastException = $ e ;
89
- } catch (Exception $ e ){
90
+ } catch (Exception $ e ) {
90
91
throw $ e ;
91
92
}
92
93
}
@@ -99,23 +100,24 @@ public function retry(Closure $closure, bool $idempotent){
99
100
*/
100
101
protected function backoffType (RetryableException $ e ): Backoff
101
102
{
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
+ // }
119
121
}
120
122
121
123
private static $ idempotentOnly = [
0 commit comments