Skip to content

Commit

Permalink
code review corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Jan 30, 2025
1 parent b97ad72 commit c145b56
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/backend/api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void ConfigureServices(IServiceCollection services)
PollyOptions pollyOptions = new();
this.Configuration.GetSection("Polly").Bind(pollyOptions);

services.AddResiliencePipeline<string, HttpResponseMessage>("retry-network-policy", (builder) =>
services.AddResiliencePipeline<string, HttpResponseMessage>(HttpRequestClient.NetworkPolicyName, (builder) =>
{
builder.AddRetry(new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Pims.Api.Models;
using Pims.Api.Models.CodeTypes;
using Pims.Api.Models.Requests.Http;
using Pims.Core.Http;
using Polly;
using Polly.Registry;

Expand Down Expand Up @@ -45,7 +46,7 @@ protected BaseRestRepository(
_logger = logger;
_httpClientFactory = httpClientFactory;
_jsonOptions = jsonOptions;
_resiliencePipeline = pollyPipelineProvider.GetPipeline<HttpResponseMessage>("retry-network-policy");
_resiliencePipeline = pollyPipelineProvider.GetPipeline<HttpResponseMessage>(HttpRequestClient.NetworkPolicyName);
}

public abstract void AddAuthentication(HttpClient client, string authenticationToken = null);
Expand Down
4 changes: 2 additions & 2 deletions source/backend/core/Http/HttpRequestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand All @@ -20,6 +19,7 @@ namespace Pims.Core.Http
public class HttpRequestClient : IHttpRequestClient
{
#region Variables
public static string NetworkPolicyName = "retry-network-policy";
protected readonly ResiliencePipeline<HttpResponseMessage> _resiliencePipeline;
private readonly JsonSerializerOptions _serializeOptions;
private readonly ILogger<HttpRequestClient> _logger;
Expand Down Expand Up @@ -52,7 +52,7 @@ public HttpRequestClient(IHttpClientFactory clientFactory, IOptionsMonitor<JsonS
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};
_logger = logger;
_resiliencePipeline = pollyPipelineProvider.GetPipeline<HttpResponseMessage>("retry-network-policy");
_resiliencePipeline = pollyPipelineProvider.GetPipeline<HttpResponseMessage>(HttpRequestClient.NetworkPolicyName);
}
#endregion

Expand Down
17 changes: 17 additions & 0 deletions source/backend/scheduler/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Security.Claims;
using System.Text;
Expand Down Expand Up @@ -32,6 +33,7 @@
using Pims.Core.Api.Handlers;
using Pims.Core.Api.Helpers;
using Pims.Core.Api.Middleware;
using Pims.Core.Configuration;
using Pims.Core.Converters;
using Pims.Core.Http;
using Pims.Core.Json;
Expand All @@ -42,6 +44,7 @@
using Pims.Scheduler.Repositories;
using Pims.Scheduler.Rescheduler;
using Pims.Scheduler.Services;
using Polly;
using Prometheus;
using StackExchange.Redis;

Expand Down Expand Up @@ -198,6 +201,20 @@ public void ConfigureServices(IServiceCollection services)
services.AddResponseCaching();
services.AddMemoryCache();

PollyOptions pollyOptions = new();
this.Configuration.GetSection("Polly").Bind(pollyOptions);

services.AddResiliencePipeline<string, HttpResponseMessage>(HttpRequestClient.NetworkPolicyName, (builder) =>
{
builder.AddRetry(new()
{
BackoffType = DelayBackoffType.Exponential,
Delay = TimeSpan.FromSeconds(pollyOptions.DelayInSeconds),
MaxRetryAttempts = pollyOptions.MaxRetries,
ShouldHandle = new PredicateBuilder<HttpResponseMessage>().Handle<HttpRequestException>().HandleResult(response => (int)response.StatusCode >= 500 && (int)response.StatusCode <= 599),
});
});

// Export metrics from all HTTP clients registered in services
services.UseHttpClientMetrics();

Expand Down
6 changes: 5 additions & 1 deletion source/backend/scheduler/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"Server": {
"HeartbeatInterval": "00:00:30",
"Queues": ["scheduler"],
"Queues": [ "scheduler" ],
"SchedulePollingInterval": "00:00:15",
"ServerCheckInterval": "00:05:00",
"ServerName": "scheduler",
Expand Down Expand Up @@ -150,5 +150,9 @@
},
"ConnectionStrings": {
"Redis": "scheduler-redis:6379"
},
"Polly": {
"MaxRetries": 3,
"DelayInSeconds": 1
}
}

0 comments on commit c145b56

Please sign in to comment.