@@ -24,31 +24,6 @@ public MembaseGraphDb(
2424
2525 private const int RetryCount = 3 ;
2626
27- private AsyncPolicy BuildRetryPolicy ( )
28- {
29- var settings = _services . GetRequiredService < MembaseSettings > ( ) ;
30- var timeoutSeconds = ( double ) settings . TimeoutSecond / RetryCount ;
31-
32- var timeoutPolicy = Policy . TimeoutAsync ( TimeSpan . FromSeconds ( timeoutSeconds ) ) ;
33-
34- var retryPolicy = Policy
35- . Handle < HttpRequestException > ( )
36- . Or < TaskCanceledException > ( )
37- . Or < TimeoutRejectedException > ( )
38- . Or < ApiException > ( ex => ex . StatusCode == HttpStatusCode . ServiceUnavailable )
39- . WaitAndRetryAsync (
40- retryCount : RetryCount ,
41- sleepDurationProvider : retryAttempt => TimeSpan . FromSeconds ( Math . Pow ( 2 , retryAttempt ) ) ,
42- onRetry : ( ex , timespan , retryAttempt , _ ) =>
43- {
44- _logger . LogWarning ( ex ,
45- "CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}" ,
46- retryAttempt , RetryCount , timespan . TotalSeconds , ex . Message ) ;
47- } ) ;
48-
49- return Policy . WrapAsync ( retryPolicy , timeoutPolicy ) ;
50- }
51-
5227 public async Task < GraphQueryResult > ExecuteQueryAsync ( string query , GraphQueryExecuteOptions ? options = null )
5328 {
5429 if ( string . IsNullOrEmpty ( options ? . GraphId ) )
@@ -87,4 +62,30 @@ public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryEx
8762 throw ;
8863 }
8964 }
65+
66+
67+ private AsyncPolicy BuildRetryPolicy ( )
68+ {
69+ var settings = _services . GetRequiredService < MembaseSettings > ( ) ;
70+ var timeoutSeconds = ( double ) settings . TimeoutSecond / RetryCount ;
71+
72+ var timeoutPolicy = Policy . TimeoutAsync ( TimeSpan . FromSeconds ( timeoutSeconds ) ) ;
73+
74+ var retryPolicy = Policy
75+ . Handle < HttpRequestException > ( )
76+ . Or < TaskCanceledException > ( )
77+ . Or < TimeoutRejectedException > ( )
78+ . Or < ApiException > ( ex => ex . StatusCode == HttpStatusCode . ServiceUnavailable )
79+ . WaitAndRetryAsync (
80+ retryCount : RetryCount ,
81+ sleepDurationProvider : retryAttempt => TimeSpan . FromSeconds ( Math . Pow ( 2 , retryAttempt ) ) ,
82+ onRetry : ( ex , timespan , retryAttempt , _ ) =>
83+ {
84+ _logger . LogWarning ( ex ,
85+ "CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}" ,
86+ retryAttempt , RetryCount , timespan . TotalSeconds , ex . Message ) ;
87+ } ) ;
88+
89+ return Policy . WrapAsync ( retryPolicy , timeoutPolicy ) ;
90+ }
9091}
0 commit comments