Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<VersionPrefix>1.0.41</VersionPrefix>

<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -23,9 +23,9 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.6" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Polly" Version="8.5.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ public void MapExceptionToStatusCode_BrokenCircuitException_MapsToServiceUnavail
}

[Fact]
public void MapExceptionToStatusCode_TypedBrokenCircuitException_MapsToServiceUnavailable()
public void MapExceptionToStatusCode_BrokenCircuitExceptionWithMessage_MapsToServiceUnavailable()
{
var statusCode = ExceptionHandlingMiddleware.MapExceptionToStatusCode(
new BrokenCircuitException<HttpResponseMessage>(
"Circuit open",
new HttpResponseMessage(HttpStatusCode.InternalServerError)));
new BrokenCircuitException("Circuit open"));

Assert.Equal(HttpStatusCode.ServiceUnavailable, statusCode);
}
Expand Down
12 changes: 6 additions & 6 deletions backend/CPS.ComplexCases.API/CPS.ComplexCases.API.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -25,14 +25,14 @@
<PackageReference Include="Microsoft.IdentityModel.Protocols" Version="8.6.1" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.6.1" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.52.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.7" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.16.3" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.7" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.10.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.5" />
<PackageReference Include="CPS.ComplexCases.API.HttpTelemetry" Version="1.0.41" />
<PackageReference Include="ThrottlingTroll.AzureFunctions" Version="9.1.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Net;
using CPS.ComplexCases.API.Clients.FileTransfer;
using CPS.ComplexCases.API.Domain.Configuration;
using CPS.ComplexCases.Common.Extensions;
using CPS.ComplexCases.Common.Resilience;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Polly;
using Polly.Contrib.WaitAndRetry;

namespace CPS.ComplexCases.API.Extensions;

Expand All @@ -25,29 +25,30 @@ public static void AddFileTransferClient(this IServiceCollection services, IConf
client.BaseAddress = new Uri(options.BaseUrl);
client.Timeout = TimeSpan.FromSeconds(options.RequestTimeoutSeconds);
})
.AddPolicyHandler((serviceProvider, request) =>
.AddResilienceHandler("file-transfer-retry", (pipeline, context) =>
{
var options = serviceProvider.GetRequiredService<IOptions<FileTransferApiOptions>>().Value;
return CreateRetryPolicy(options);
var options = context.ServiceProvider.GetRequiredService<IOptions<FileTransferApiOptions>>().Value;
var logger = context.ServiceProvider
.GetRequiredService<ILoggerFactory>()
.CreateLogger("CPS.ComplexCases.API.FileTransfer");

// Shared helper keeps POST/PUT out of status-code retries. Circuit breaker is off —
// FileTransfer only needs the common retry policy, not fail-fast shedding.
pipeline.AddStandardHttpResilience(new HttpResilienceOptions
{
ServiceName = "FileTransfer",
RetryAttempts = options.RetryAttempts > 0 ? options.RetryAttempts : 2,
FirstRetryDelay = TimeSpan.FromSeconds(
options.FirstRetryDelaySeconds > 0 ? options.FirstRetryDelaySeconds : 1),
CircuitBreakerFailureThreshold = 0.5,
CircuitBreakerSamplingDuration = TimeSpan.FromSeconds(30),
CircuitBreakerMinimumThroughput = 10,
CircuitBreakerDurationOfBreak = TimeSpan.FromSeconds(30),
EnableCircuitBreaker = false,
ConcurrencyLimit = 0,
}, logger);
});

services.AddTransient<IRequestFactory, RequestFactory>();
}

private static IAsyncPolicy<HttpResponseMessage> CreateRetryPolicy(FileTransferApiOptions options)
{
var retryAttempts = options.RetryAttempts > 0 ? options.RetryAttempts : 2;
var firstRetryDelaySeconds = options.FirstRetryDelaySeconds > 0 ? options.FirstRetryDelaySeconds : 1;

return Policy
.HandleResult<HttpResponseMessage>(ShouldRetry)
.WaitAndRetryAsync(Backoff.DecorrelatedJitterBackoffV2(
medianFirstRetryDelay: TimeSpan.FromSeconds(firstRetryDelaySeconds),
retryCount: retryAttempts));
}

private static bool ShouldRetry(HttpResponseMessage response)
{
return response.StatusCode >= HttpStatusCode.InternalServerError;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ByteSize" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CPS.ComplexCases.Common\CPS.ComplexCases.Common.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Loading
Loading