1- /*
1+ /*
22 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License").
55 * You may not use this file except in compliance with the License.
66 * A copy of the License is located at
7- *
7+ *
88 * http://aws.amazon.com/apache2.0
9- *
9+ *
1010 * or in the "license" file accompanying this file. This file is distributed
1111 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1212 * express or implied. See the License for the specific language governing
1313 * permissions and limitations under the License.
1414 */
1515
1616using System ;
17- using System . Collections . Generic ;
18- using System . Linq ;
19- using System . Text ;
20-
17+ using System . Threading . Tasks ;
2118using Amazon . Runtime ;
2219using Amazon . Runtime . Internal ;
2320
@@ -38,12 +35,12 @@ public DynamoDBRetryPolicy(IClientConfig config) :
3835 base ( config )
3936 {
4037 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
4340 //mode. When in legacy retry mode MaxErrorRetry used to be set
4441 //to 10 in the DynamoDB and DynamoDBStreams configs. This
4542 //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
4744 //retry modes are not to have this default.
4845 if ( ! config . IsMaxErrorRetrySet )
4946 {
@@ -57,24 +54,32 @@ public DynamoDBRetryPolicy(IClientConfig config) :
5754 /// <param name="executionContext"></param>
5855 public override void WaitBeforeRetry ( IExecutionContext executionContext )
5956 {
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 ) ;
6167 }
6268
6369 /// <summary>
6470 /// Override the pausing function so retries would happen more frequent then the default operation.
6571 /// </summary>
66- /// <param name="retries">Current number of retries.</param>
67- private void pauseExponentially ( int retries )
72+ private int CalculateRetryDelay ( int retries )
6873 {
6974 int delay ;
70-
75+
7176 if ( retries <= 0 ) delay = 0 ;
7277 else if ( retries < 20 ) delay = Convert . ToInt32 ( Math . Pow ( 2 , retries - 1 ) * 50.0 ) ;
7378 else delay = Int32 . MaxValue ;
7479
7580 if ( retries > 0 && ( delay > MaxBackoffInMilliseconds || delay <= 0 ) )
7681 delay = MaxBackoffInMilliseconds ;
77- Amazon . Util . AWSSDKUtils . Sleep ( delay ) ;
82+ return delay ;
7883 }
7984 }
8085}
0 commit comments