Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created January 13, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/a6f178199d1ab91be926 to your computer and use it in GitHub Desktop.
Save vendettamit/a6f178199d1ab91be926 to your computer and use it in GitHub Desktop.
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