Created
January 13, 2016 21:41
-
-
Save vendettamit/a6f178199d1ab91be926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeedDao | |
{ | |
private readonly RetryPolicy retryPolicy; | |
public FeedDao() | |
{ | |
// setup retry policy that will try 3 times, with fast retry for first time and then | |
// with incremental interval by 1.5 seconds. | |
this.retryPolicy = | |
new RetryPolicy<DownloadFeedTrasientErrorDetectionStrategy>( | |
new Incremental(3, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1.5)) | |
{ | |
FastFirstRetry = true | |
}); | |
// Set tracing if retry happened. | |
this.retryPolicy.Retrying += (s, e) => | |
Trace.TraceWarning("An error occurred in attempt number {1} to download feed: {0}", e.LastException.Message, e.CurrentRetryCount); | |
} | |
public void GetFeed() | |
{ | |
this.retryPolicy.ExecuteAction(() => this.DownloadFeed(feed_source)); | |
} | |
private string DownloadFeed(string source) | |
{ | |
// logic to retrieve feeds | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment