@@ -77,22 +77,26 @@ public function retry(Closure $closure, bool $idempotent)
77
77
$ startTime = microtime (true );
78
78
$ retryCount = 0 ;
79
79
$ lastException = null ;
80
- while (microtime (true ) < $ startTime + $ this ->timeoutMs / 1000 ) {
80
+ $ deadline = is_null ($ this ->timeoutMs ) ? PHP_INT_MAX : $ startTime + $ this ->timeoutMs / 1000 ;
81
+ $ this ->logger ->debug ("YDB: begin retry function. Deadline: $ deadline " );
82
+ do {
81
83
$ this ->logger ->debug ("YDB: Run user function. Retry count: $ retryCount. s: " .(microtime (true ) - $ startTime ));
82
84
try {
83
85
return $ closure ();
84
- } catch (Exception $ e ) {
85
- $ this ->logger ->warning ("YDB: Received exception: " .$ e ->getMessage ());
86
+ } catch (\Exception $ e ) {
87
+ $ this ->logger ->debug ("YDB: Received exception: " .$ e ->getMessage ());
88
+ $ lastException = $ e ;
86
89
if (!$ this ->canRetry ($ e , $ idempotent )){
87
- $ lastException = $ e ;
88
90
break ;
89
91
}
90
92
$ retryCount ++;
91
- $ lastException = $ e ;
92
93
$ delay = $ this ->retryDelay ($ retryCount , $ this ->backoffType (get_class ($ e )))*1000 ;
94
+ $ this ->logger ->debug ("YDB: Sleep $ delay microseconds before retry " );
93
95
usleep ($ delay );
94
96
}
95
- }
97
+ } while (microtime (true ) < $ deadline );
98
+ $ this ->logger ->error ("YDB: Timeout retry function. ms: "
99
+ .((microtime (true )-$ startTime )*1000 ). "Retry count: $ retryCount " );
96
100
throw $ lastException ;
97
101
}
98
102
@@ -111,7 +115,7 @@ protected function alwaysRetry(string $exception)
111
115
return in_array ($ exception , self ::$ alwaysRetry );
112
116
}
113
117
114
- protected function canRetry (Exception $ e , bool $ idempotent )
118
+ protected function canRetry (\ Exception $ e , bool $ idempotent )
115
119
{
116
120
return is_a ($ e , RetryableException::class) && ($ this ->alwaysRetry (get_class ($ e )) || $ idempotent );
117
121
}
0 commit comments