public static Forecast RetryAndWaitPolicyExample() { /* * This will try to execute the service, and retry every three seconds after each failure. On each failure, * the policy adds additional three seconds to the wait time. */ var result = RetryPolicy.GetRetryAndWaitPolicy() .Execute(() => _weatherService.GetForecast(true)); return(result); }
public static Forecast WrapPoliciesExample() { var retryPolicy = RetryPolicy.GetRetryPolicy(1); var retryAndWaitPolicy = RetryPolicy.GetRetryAndWaitPolicy(1); var fallbackPolicy = FallbackPolicy.GetFallbackPolicy(_fallbackWeatherService.GetForecast); // Policy Wrap can combine multiple policies. // In this example, try retrying immediately first, then wait N seconds to retry, and if that fails, use a fallback. // Policy run order is from the latest wrapped to the first wrapped. // This will execute retry, then retryAndWait and finally fallback. var policyWrap = fallbackPolicy.Wrap(retryAndWaitPolicy).Wrap(retryPolicy); var result = policyWrap.Execute(() => _weatherService.GetForecast(true)); return(result); }