Skip to content

Commit

Permalink
Fix remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
hogwartsdeveloper committed May 28, 2024
1 parent 5c18640 commit 596793d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
19 changes: 19 additions & 0 deletions src/Ocelot.Provider.Polly/PollyQoSProviderBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
using Ocelot.Configuration;
using Ocelot.Configuration.File;
using System.Net;

namespace Ocelot.Provider.Polly;

public abstract class PollyQoSProviderBase
{
protected PollyQoSProviderBase(FileGlobalConfiguration global)
{
_global = global;
_requestTimeoutSeconds = _global.RequestTimeoutSeconds;
}

protected readonly FileGlobalConfiguration _global;

protected const int DefaultRequestTimeoutSeconds = 90;

private int? _requestTimeoutSeconds;

protected int RequestTimeoutSeconds
{
get => _requestTimeoutSeconds ?? _global?.RequestTimeoutSeconds ?? DefaultRequestTimeoutSeconds;
set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds;
}

protected static readonly HashSet<HttpStatusCode> ServerErrorCodes = new()
{
HttpStatusCode.InternalServerError,
Expand Down
15 changes: 4 additions & 11 deletions src/Ocelot.Provider.Polly/PollyQoSResiliencePipelineProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Options;
using Ocelot.Configuration;
using Ocelot.Configuration.File;
using Ocelot.Logging;
Expand All @@ -11,24 +12,16 @@ namespace Ocelot.Provider.Polly;
/// <summary>
/// Default provider for Polly V8 pipelines.
/// </summary>
public class PollyQoSResiliencePipelineProvider : PollyQoSProviderBase, IPollyQoSResiliencePipelineProvider<HttpResponseMessage>
public class PollyQoSResiliencePipelineProvider
: PollyQoSProviderBase, IPollyQoSResiliencePipelineProvider<HttpResponseMessage>
{
private readonly ResiliencePipelineRegistry<OcelotResiliencePipelineKey> _resiliencePipelineRegistry;
private readonly IOcelotLogger _logger;

public const int DefaultRequestTimeoutSeconds = 90;
private int _requestTimeoutSeconds;

public int RequestTimeoutSeconds
{
get => _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds;
set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds;
}

public PollyQoSResiliencePipelineProvider(
IOcelotLoggerFactory loggerFactory,
ResiliencePipelineRegistry<OcelotResiliencePipelineKey> resiliencePipelineRegistry,
FileGlobalConfiguration fileGlobalConfigure)
IOptions<FileGlobalConfiguration> global) : base(global.Value)
{
_resiliencePipelineRegistry = resiliencePipelineRegistry;
_logger = loggerFactory.CreateLogger<PollyQoSResiliencePipelineProvider>();
Expand Down
18 changes: 5 additions & 13 deletions src/Ocelot.Provider.Polly/v7/PollyQoSProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ocelot.Configuration;
using Microsoft.Extensions.Options;
using Ocelot.Configuration;
using Ocelot.Configuration.File;
using Ocelot.Logging;
using Polly.CircuitBreaker;
Expand All @@ -15,21 +16,12 @@ public class PollyQoSProvider : PollyQoSProviderBase, IPollyQoSProvider<HttpResp

private readonly object _lockObject = new();
private readonly IOcelotLogger _logger;

public const int DefaultRequestTimeoutSeconds = 90;

private int _requestTimeoutSeconds;

public int RequestTimeoutSeconds
{
get => _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds;
set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds;
}

public PollyQoSProvider(IOcelotLoggerFactory loggerFactory, FileGlobalConfiguration fileGlobalConfiguration)
public PollyQoSProvider(
IOcelotLoggerFactory loggerFactory,
IOptions<FileGlobalConfiguration> global) : base(global.Value)
{
_logger = loggerFactory.CreateLogger<PollyQoSProvider>();
RequestTimeoutSeconds = fileGlobalConfiguration.RequestTimeoutSeconds ?? 0;
}

[Obsolete("Due to new v8 policy definition in Polly 8 (use GetResiliencePipeline in PollyQoSResiliencePipelineProvider)")]
Expand Down

0 comments on commit 596793d

Please sign in to comment.