| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.Batch.Common |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Represents a decision made by an <see cref="IRetryPolicy"/>. |
| | 10 | | /// </summary> |
| | 11 | | public sealed class RetryDecision |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// A retry decision with <see cref="ShouldRetry"/> set to false |
| | 15 | | /// </summary> |
| 1 | 16 | | public static readonly RetryDecision NoRetry = new RetryDecision(); |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Create a new <see cref="RetryDecision"/> with the specified delay before the next retry. |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="retryDelay">The duration to wait before performing the retry.</param> |
| | 22 | | /// <returns>A <see cref="RetryDecision"/> object with the specified retry delay and <see cref="ShouldRetry"/> s |
| | 23 | | public static RetryDecision RetryWithDelay(TimeSpan retryDelay) |
| | 24 | | { |
| 45 | 25 | | return new RetryDecision(retryDelay); |
| | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets the delay before the next retry. |
| | 30 | | /// </summary> |
| 115 | 31 | | public TimeSpan? RetryDelay { get; private set; } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets whether a retry should be performed or not. |
| | 35 | | /// </summary> |
| 121 | 36 | | public bool ShouldRetry { get; private set; } |
| | 37 | |
|
| | 38 | |
|
| 1 | 39 | | private RetryDecision() |
| | 40 | | { |
| 1 | 41 | | this.ShouldRetry = false; |
| 1 | 42 | | this.RetryDelay = null; |
| 1 | 43 | | } |
| | 44 | |
|
| 45 | 45 | | private RetryDecision(TimeSpan retryDelay) |
| | 46 | | { |
| 45 | 47 | | this.ShouldRetry = true; |
| 45 | 48 | | this.RetryDelay = retryDelay; |
| 45 | 49 | | } |
| | 50 | |
|
| | 51 | | } |
| | 52 | | } |