1
- /*
1
+ /*
2
2
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
3
+ *
4
4
* Licensed under the Apache License, Version 2.0 (the "License").
5
5
* You may not use this file except in compliance with the License.
6
6
* A copy of the License is located at
7
- *
7
+ *
8
8
* http://aws.amazon.com/apache2.0
9
- *
9
+ *
10
10
* or in the "license" file accompanying this file. This file is distributed
11
11
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
12
* express or implied. See the License for the specific language governing
13
13
* permissions and limitations under the License.
14
14
*/
15
15
16
16
using System ;
17
- using System . Collections . Generic ;
18
- using System . Linq ;
19
- using System . Text ;
20
-
17
+ using System . Threading . Tasks ;
21
18
using Amazon . Runtime ;
22
19
using Amazon . Runtime . Internal ;
23
20
@@ -38,12 +35,12 @@ public DynamoDBRetryPolicy(IClientConfig config) :
38
35
base ( config )
39
36
{
40
37
ThrottlingErrorCodes . Add ( "TransactionInProgressException" ) ;
41
-
42
- //When derived from DefaultRetryPolicy, we are in legacy retry
38
+
39
+ //When derived from DefaultRetryPolicy, we are in legacy retry
43
40
//mode. When in legacy retry mode MaxErrorRetry used to be set
44
41
//to 10 in the DynamoDB and DynamoDBStreams configs. This
45
42
//can no longer be set in the configs because the retry mode
46
- //may not be known at that point where standard and adaptive
43
+ //may not be known at that point where standard and adaptive
47
44
//retry modes are not to have this default.
48
45
if ( ! config . IsMaxErrorRetrySet )
49
46
{
@@ -57,24 +54,32 @@ public DynamoDBRetryPolicy(IClientConfig config) :
57
54
/// <param name="executionContext"></param>
58
55
public override void WaitBeforeRetry ( IExecutionContext executionContext )
59
56
{
60
- pauseExponentially ( executionContext . RequestContext . Retries ) ;
57
+ Amazon . Util . AWSSDKUtils . Sleep ( CalculateRetryDelay ( executionContext . RequestContext . Retries ) ) ;
58
+ }
59
+
60
+ /// <summary>
61
+ /// Overriden to cause a pause between retries.
62
+ /// </summary>
63
+ /// <param name="executionContext"></param>
64
+ public override Task WaitBeforeRetryAsync ( IExecutionContext executionContext )
65
+ {
66
+ return Task . Delay ( CalculateRetryDelay ( executionContext . RequestContext . Retries ) , executionContext . RequestContext . CancellationToken ) ;
61
67
}
62
68
63
69
/// <summary>
64
70
/// Override the pausing function so retries would happen more frequent then the default operation.
65
71
/// </summary>
66
- /// <param name="retries">Current number of retries.</param>
67
- private void pauseExponentially ( int retries )
72
+ private int CalculateRetryDelay ( int retries )
68
73
{
69
74
int delay ;
70
-
75
+
71
76
if ( retries <= 0 ) delay = 0 ;
72
77
else if ( retries < 20 ) delay = Convert . ToInt32 ( Math . Pow ( 2 , retries - 1 ) * 50.0 ) ;
73
78
else delay = Int32 . MaxValue ;
74
79
75
80
if ( retries > 0 && ( delay > MaxBackoffInMilliseconds || delay <= 0 ) )
76
81
delay = MaxBackoffInMilliseconds ;
77
- Amazon . Util . AWSSDKUtils . Sleep ( delay ) ;
82
+ return delay ;
78
83
}
79
84
}
80
85
}
0 commit comments