< Summary

Information
Class: Elsa.Http.Resilience.HttpResilienceStrategy
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Resilience/HttpResilienceStrategy.cs
Line coverage
95%
Covered lines: 21
Uncovered lines: 1
Coverable lines: 22
Total lines: 39
Line coverage: 95.4%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_DisplayName()100%11100%
get_MaxRetryAttempts()100%11100%
get_UseJitter()100%11100%
get_Delay()100%11100%
get_BackoffType()100%11100%
ConfigurePipeline(...)75%4493.75%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Resilience/HttpResilienceStrategy.cs

#LineLine coverage
 1using Elsa.Http.Extensions;
 2using Elsa.Resilience;
 3using Polly;
 4using Polly.Retry;
 5
 6namespace Elsa.Http.Resilience;
 7
 8[ResilienceCategory("HTTP")]
 9public class HttpResilienceStrategy : IResilienceStrategy
 10{
 311    public string Id { get; set; } = null!;
 312    public string DisplayName { get; set; } = null!;
 413    public int MaxRetryAttempts { get; set; } = 3;
 214    public bool UseJitter { get; set; }
 415    public TimeSpan Delay { get; set; } = TimeSpan.FromSeconds(1);
 316    public DelayBackoffType BackoffType { get; set; } = DelayBackoffType.Exponential;
 17
 18    public Task ConfigurePipeline<T>(ResiliencePipelineBuilder<T> pipelineBuilder, ResilienceContext context)
 19    {
 120        if (typeof(T) != typeof(HttpResponseMessage))
 021            throw new NotSupportedException($"{nameof(HttpResilienceStrategy)} only supports HttpResponseMessage.");
 22
 123        var options = new RetryStrategyOptions<T>
 124        {
 125            ShouldHandle = new PredicateBuilder<T>()
 126                .Handle<TimeoutException>()
 127                .Handle<HttpRequestException>()
 328                .HandleResult(response => ((HttpResponseMessage)(object)response!).StatusCode.IsTransientStatusCode()),
 129            MaxRetryAttempts = MaxRetryAttempts,
 130            Delay = Delay,
 131            UseJitter = UseJitter,
 132            BackoffType = BackoffType,
 133            Name = DisplayName
 134        };
 35
 136        pipelineBuilder.AddRetry(options);
 137        return Task.CompletedTask;
 38    }
 39}