Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Attempt to AttemptNumber #1447

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/Polly.Core/Hedging/Controller/HedgingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal sealed record class HedgingHandler<T>(
var copiedArgs = new HedgingActionGeneratorArguments<T>(
args.PrimaryContext,
args.ActionContext,
args.Attempt,
args.AttemptNumber,
(Func<ResilienceContext, ValueTask<Outcome<T>>>)(object)args.Callback);

return (Func<ValueTask<Outcome<T>>>?)(object)ActionGenerator(copiedArgs)!;
Expand All @@ -24,7 +24,7 @@ internal sealed record class HedgingHandler<T>(
private Func<ValueTask<Outcome<T>>>? CreateNonGenericAction(HedgingActionGeneratorArguments<T> args)
{
var generator = (Func<HedgingActionGeneratorArguments<object>, Func<ValueTask<Outcome<object>>>?>)(object)ActionGenerator;
var action = generator(new HedgingActionGeneratorArguments<object>(args.PrimaryContext, args.ActionContext, args.Attempt, async context =>
var action = generator(new HedgingActionGeneratorArguments<object>(args.PrimaryContext, args.ActionContext, args.AttemptNumber, async context =>
{
var outcome = await args.Callback(context).ConfigureAwait(context.ContinueOnCapturedContext);
return outcome.AsOutcome();
Expand Down
12 changes: 6 additions & 6 deletions src/Polly.Core/Hedging/Controller/TaskExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public TaskExecution(HedgingHandler<T> handler, CancellationTokenSourcePool canc

public TimeSpan ExecutionTime => _timeProvider.GetElapsedTime(_startExecutionTimestamp, _stopExecutionTimestamp);

public int Attempt { get; private set; }
public int AttemptNumber { get; private set; }

public void AcceptOutcome()
{
Expand All @@ -92,9 +92,9 @@ public async ValueTask<bool> InitializeAsync<TState>(
ContextSnapshot snapshot,
Func<ResilienceContext, TState, ValueTask<Outcome<T>>> primaryCallback,
TState state,
int attempt)
int attemptNumber)
{
Attempt = attempt;
AttemptNumber = attemptNumber;
Type = type;
_cancellationSource = _cancellationTokenSourcePool.Get(System.Threading.Timeout.InfiniteTimeSpan);
_startExecutionTimestamp = _timeProvider.GetTimestamp();
Expand All @@ -113,7 +113,7 @@ public async ValueTask<bool> InitializeAsync<TState>(

try
{
action = _handler.GenerateAction(CreateArguments(primaryCallback, snapshot.Context, state, attempt));
action = _handler.GenerateAction(CreateArguments(primaryCallback, snapshot.Context, state, attemptNumber));
if (action == null)
{
await ResetAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -178,7 +178,7 @@ public async ValueTask ResetAsync()
IsHandled = false;
Properties.Clear();
OnReset = null;
Attempt = 0;
AttemptNumber = 0;
_activeContext = null;
_cachedContext.Reset();
_cancellationSource = null!;
Expand Down Expand Up @@ -227,7 +227,7 @@ private async Task UpdateOutcomeAsync(Outcome<T> outcome)
var args = new OutcomeArguments<T, HedgingPredicateArguments>(Context, outcome, default);
Outcome = outcome.AsOutcome();
IsHandled = await _handler.ShouldHandle(args).ConfigureAwait(Context.ContinueOnCapturedContext);
TelemetryUtil.ReportExecutionAttempt(_telemetry, Context, outcome, Attempt, ExecutionTime, IsHandled);
TelemetryUtil.ReportExecutionAttempt(_telemetry, Context, outcome, AttemptNumber, ExecutionTime, IsHandled);
}

private void PrepareContext(ref ContextSnapshot snapshot)
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public readonly struct HedgingActionGeneratorArguments<TResult>
/// <param name="actionContext">
/// The context that will be passed to action generated by <see cref="HedgingStrategyOptions{TResult}.HedgingActionGenerator"/>.
/// .</param>
/// <param name="attempt">The zero-based hedging attempt number.</param>
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
/// <param name="callback">The callback passed to hedging strategy.</param>
public HedgingActionGeneratorArguments(
ResilienceContext primaryContext,
ResilienceContext actionContext,
int attempt,
int attemptNumber,
Func<ResilienceContext, ValueTask<Outcome<TResult>>> callback)
{
PrimaryContext = primaryContext;
ActionContext = actionContext;
Attempt = attempt;
AttemptNumber = attemptNumber;
Callback = callback;
}

Expand All @@ -48,7 +48,7 @@ public HedgingActionGeneratorArguments(
/// <summary>
/// Gets the zero-based hedging attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }

/// <summary>
/// Gets the callback passed to hedging strategy.
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Hedging/HedgingDelayArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public readonly struct HedgingDelayArguments
/// Initializes a new instance of the <see cref="HedgingDelayArguments"/> struct.
/// </summary>
/// <param name="context">The context associated with the execution of a user-provided callback.</param>
/// <param name="attempt">The zero-based hedging attempt number.</param>
public HedgingDelayArguments(ResilienceContext context, int attempt)
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
public HedgingDelayArguments(ResilienceContext context, int attemptNumber)
{
Context = context;
Attempt = attempt;
AttemptNumber = attemptNumber;
}

/// <summary>
Expand All @@ -29,5 +29,5 @@ public HedgingDelayArguments(ResilienceContext context, int attempt)
/// <summary>
/// Gets the zero-based hedging attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }
}
8 changes: 4 additions & 4 deletions src/Polly.Core/Hedging/OnHedgingArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public sealed class OnHedgingArguments
/// <summary>
/// Initializes a new instance of the <see cref="OnHedgingArguments"/> class.
/// </summary>
/// <param name="attempt">The zero-based hedging attempt number.</param>
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
/// <param name="hasOutcome">Indicates whether outcome is available.</param>
/// <param name="executionTime">The execution time of hedging attempt or the hedging delay in case the attempt was not finished in time.</param>
public OnHedgingArguments(int attempt, bool hasOutcome, TimeSpan executionTime)
public OnHedgingArguments(int attemptNumber, bool hasOutcome, TimeSpan executionTime)
{
Attempt = attempt;
AttemptNumber = attemptNumber;
HasOutcome = hasOutcome;
ExecutionTime = executionTime;
}

/// <summary>
/// Gets the zero-based hedging attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }

/// <summary>
/// Gets a value indicating whether the outcome is available before loading the next hedged task.
Expand Down
33 changes: 16 additions & 17 deletions src/Polly.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy<TResult>(TKey key, out Polly.ResilienceStrategy<TResult>? strategy) -> bool
abstract Polly.ResilienceContextPool.Get(string? operationKey, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Polly.ResilienceContext!
abstract Polly.ResilienceContextPool.Return(Polly.ResilienceContext! context) -> void
Expand Down Expand Up @@ -94,16 +93,16 @@ Polly.Fallback.OnFallbackArguments.OnFallbackArguments() -> void
Polly.FallbackResilienceStrategyBuilderExtensions
Polly.Hedging.HedgingActionGeneratorArguments<TResult>
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.ActionContext.get -> Polly.ResilienceContext!
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.Attempt.get -> int
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.AttemptNumber.get -> int
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.Callback.get -> System.Func<Polly.ResilienceContext!, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>!
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.HedgingActionGeneratorArguments() -> void
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.HedgingActionGeneratorArguments(Polly.ResilienceContext! primaryContext, Polly.ResilienceContext! actionContext, int attempt, System.Func<Polly.ResilienceContext!, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback) -> void
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.HedgingActionGeneratorArguments(Polly.ResilienceContext! primaryContext, Polly.ResilienceContext! actionContext, int attemptNumber, System.Func<Polly.ResilienceContext!, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback) -> void
Polly.Hedging.HedgingActionGeneratorArguments<TResult>.PrimaryContext.get -> Polly.ResilienceContext!
Polly.Hedging.HedgingDelayArguments
Polly.Hedging.HedgingDelayArguments.Attempt.get -> int
Polly.Hedging.HedgingDelayArguments.AttemptNumber.get -> int
Polly.Hedging.HedgingDelayArguments.Context.get -> Polly.ResilienceContext!
Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments() -> void
Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments(Polly.ResilienceContext! context, int attempt) -> void
Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments(Polly.ResilienceContext! context, int attemptNumber) -> void
Polly.Hedging.HedgingPredicateArguments
Polly.Hedging.HedgingPredicateArguments.HedgingPredicateArguments() -> void
Polly.Hedging.HedgingStrategyOptions<TResult>
Expand All @@ -121,10 +120,10 @@ Polly.Hedging.HedgingStrategyOptions<TResult>.OnHedging.set -> void
Polly.Hedging.HedgingStrategyOptions<TResult>.ShouldHandle.get -> System.Func<Polly.OutcomeArguments<TResult, Polly.Hedging.HedgingPredicateArguments>, System.Threading.Tasks.ValueTask<bool>>!
Polly.Hedging.HedgingStrategyOptions<TResult>.ShouldHandle.set -> void
Polly.Hedging.OnHedgingArguments
Polly.Hedging.OnHedgingArguments.Attempt.get -> int
Polly.Hedging.OnHedgingArguments.AttemptNumber.get -> int
Polly.Hedging.OnHedgingArguments.ExecutionTime.get -> System.TimeSpan
Polly.Hedging.OnHedgingArguments.HasOutcome.get -> bool
Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int attempt, bool hasOutcome, System.TimeSpan executionTime) -> void
Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int attemptNumber, bool hasOutcome, System.TimeSpan executionTime) -> void
Polly.HedgingResilienceStrategyBuilderExtensions
Polly.NullResilienceStrategy
Polly.NullResilienceStrategy<TResult>
Expand Down Expand Up @@ -279,32 +278,32 @@ Polly.ResilienceStrategyBuilderContext.StrategyName.get -> string?
Polly.ResilienceStrategyBuilderContext.Telemetry.get -> Polly.Telemetry.ResilienceStrategyTelemetry!
Polly.ResilienceStrategyBuilderExtensions
Polly.ResilienceStrategyOptions
Polly.ResilienceStrategyOptions.ResilienceStrategyOptions() -> void
Polly.ResilienceStrategyOptions.Name.get -> string?
Polly.ResilienceStrategyOptions.Name.set -> void
Polly.ResilienceStrategyOptions.ResilienceStrategyOptions() -> void
Polly.ResilienceValidationContext
Polly.ResilienceValidationContext.Instance.get -> object!
Polly.ResilienceValidationContext.PrimaryMessage.get -> string!
Polly.ResilienceValidationContext.ResilienceValidationContext(object! instance, string! primaryMessage) -> void
Polly.Retry.OnRetryArguments
Polly.Retry.OnRetryArguments.Attempt.get -> int
Polly.Retry.OnRetryArguments.AttemptNumber.get -> int
Polly.Retry.OnRetryArguments.ExecutionTime.get -> System.TimeSpan
Polly.Retry.OnRetryArguments.OnRetryArguments(int attempt, System.TimeSpan retryDelay, System.TimeSpan executionTime) -> void
Polly.Retry.OnRetryArguments.OnRetryArguments(int attemptNumber, System.TimeSpan retryDelay, System.TimeSpan executionTime) -> void
Polly.Retry.OnRetryArguments.RetryDelay.get -> System.TimeSpan
Polly.Retry.RetryBackoffType
Polly.Retry.RetryBackoffType.Constant = 0 -> Polly.Retry.RetryBackoffType
Polly.Retry.RetryBackoffType.Exponential = 2 -> Polly.Retry.RetryBackoffType
Polly.Retry.RetryBackoffType.ExponentialWithJitter = 3 -> Polly.Retry.RetryBackoffType
Polly.Retry.RetryBackoffType.Linear = 1 -> Polly.Retry.RetryBackoffType
Polly.Retry.RetryDelayArguments
Polly.Retry.RetryDelayArguments.Attempt.get -> int
Polly.Retry.RetryDelayArguments.AttemptNumber.get -> int
Polly.Retry.RetryDelayArguments.DelayHint.get -> System.TimeSpan
Polly.Retry.RetryDelayArguments.RetryDelayArguments() -> void
Polly.Retry.RetryDelayArguments.RetryDelayArguments(int attempt, System.TimeSpan delayHint) -> void
Polly.Retry.RetryDelayArguments.RetryDelayArguments(int attemptNumber, System.TimeSpan delayHint) -> void
Polly.Retry.RetryPredicateArguments
Polly.Retry.RetryPredicateArguments.Attempt.get -> int
Polly.Retry.RetryPredicateArguments.AttemptNumber.get -> int
Polly.Retry.RetryPredicateArguments.RetryPredicateArguments() -> void
Polly.Retry.RetryPredicateArguments.RetryPredicateArguments(int attempt) -> void
Polly.Retry.RetryPredicateArguments.RetryPredicateArguments(int attemptNumber) -> void
Polly.Retry.RetryStrategyOptions
Polly.Retry.RetryStrategyOptions.RetryStrategyOptions() -> void
Polly.Retry.RetryStrategyOptions<TResult>
Expand All @@ -323,8 +322,8 @@ Polly.Retry.RetryStrategyOptions<TResult>.ShouldHandle.get -> System.Func<Polly.
Polly.Retry.RetryStrategyOptions<TResult>.ShouldHandle.set -> void
Polly.RetryResilienceStrategyBuilderExtensions
Polly.Telemetry.ExecutionAttemptArguments
Polly.Telemetry.ExecutionAttemptArguments.Attempt.get -> int
Polly.Telemetry.ExecutionAttemptArguments.ExecutionAttemptArguments(int attempt, System.TimeSpan executionTime, bool handled) -> void
Polly.Telemetry.ExecutionAttemptArguments.AttemptNumber.get -> int
Polly.Telemetry.ExecutionAttemptArguments.ExecutionAttemptArguments(int attemptNumber, System.TimeSpan executionTime, bool handled) -> void
Polly.Telemetry.ExecutionAttemptArguments.ExecutionTime.get -> System.TimeSpan
Polly.Telemetry.ExecutionAttemptArguments.Handled.get -> bool
Polly.Telemetry.ResilienceEvent
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Retry/OnRetryArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public sealed class OnRetryArguments
/// <summary>
/// Initializes a new instance of the <see cref="OnRetryArguments"/> class.
/// </summary>
/// <param name="attempt">The zero-based attempt number.</param>
/// <param name="attemptNumber">The zero-based attempt number.</param>
/// <param name="retryDelay">The delay before the next retry.</param>
/// <param name="executionTime">The execution time of this attempt.</param>
public OnRetryArguments(int attempt, TimeSpan retryDelay, TimeSpan executionTime)
public OnRetryArguments(int attemptNumber, TimeSpan retryDelay, TimeSpan executionTime)
{
Attempt = attempt;
AttemptNumber = attemptNumber;
RetryDelay = retryDelay;
ExecutionTime = executionTime;
}

/// <summary>
/// Gets the zero-based attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }

/// <summary>
/// Gets the delay before the next retry.
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Retry/RetryDelayArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ public readonly struct RetryDelayArguments
/// <summary>
/// Initializes a new instance of the <see cref="RetryDelayArguments"/> struct.
/// </summary>
/// <param name="attempt">The zero-based attempt number.</param>
/// <param name="attemptNumber">The zero-based attempt number.</param>
/// <param name="delayHint">The delay suggested by the retry strategy.</param>
public RetryDelayArguments(int attempt, TimeSpan delayHint)
public RetryDelayArguments(int attemptNumber, TimeSpan delayHint)
{
Attempt = attempt;
AttemptNumber = attemptNumber;
DelayHint = delayHint;
}

/// <summary>
/// Gets The zero-based attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }

/// <summary>
/// Gets the delay suggested by the retry strategy.
Expand Down
6 changes: 3 additions & 3 deletions src/Polly.Core/Retry/RetryPredicateArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public readonly struct RetryPredicateArguments
/// <summary>
/// Initializes a new instance of the <see cref="RetryPredicateArguments"/> struct.
/// </summary>
/// <param name="attempt">The zero-based attempt number.</param>
public RetryPredicateArguments(int attempt) => Attempt = attempt;
/// <param name="attemptNumber">The zero-based attempt number.</param>
public RetryPredicateArguments(int attemptNumber) => AttemptNumber = attemptNumber;

/// <summary>
/// Gets the zero-based attempt number.
/// </summary>
public int Attempt { get; }
public int AttemptNumber { get; }
}
4 changes: 2 additions & 2 deletions src/Polly.Core/Telemetry/ExecutionAttemptArguments.Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ public partial class ExecutionAttemptArguments
private static readonly ObjectPool<ExecutionAttemptArguments> Pool = new(() => new ExecutionAttemptArguments(), args =>
{
args.ExecutionTime = TimeSpan.Zero;
args.Attempt = 0;
args.AttemptNumber = 0;
args.Handled = false;
});

internal static ExecutionAttemptArguments Get(int attempt, TimeSpan executionTime, bool handled)
{
var args = Pool.Get();
args.Attempt = attempt;
args.AttemptNumber = attempt;
args.ExecutionTime = executionTime;
args.Handled = handled;
return args;
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Telemetry/ExecutionAttemptArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public partial class ExecutionAttemptArguments
/// <summary>
/// Initializes a new instance of the <see cref="ExecutionAttemptArguments"/> class.
/// </summary>
/// <param name="attempt">The execution attempt.</param>
/// <param name="attemptNumber">The execution attempt.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <param name="attemptNumber">The execution attempt.</param>
/// <param name="attemptNumber">The execution attempt number.</param>

/// <param name="executionTime">The execution time.</param>
/// <param name="handled">Determines whether the attempt was handled by the strategy.</param>
public ExecutionAttemptArguments(int attempt, TimeSpan executionTime, bool handled)
public ExecutionAttemptArguments(int attemptNumber, TimeSpan executionTime, bool handled)
{
Attempt = attempt;
AttemptNumber = attemptNumber;
ExecutionTime = executionTime;
Handled = handled;
}
Expand All @@ -25,7 +25,7 @@ private ExecutionAttemptArguments()
/// <summary>
/// Gets the attempt number.
/// </summary>
public int Attempt { get; private set; }
public int AttemptNumber { get; private set; }

/// <summary>
/// Gets the execution time of the attempt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void MeterEvent(TelemetryEventArguments args)

var enrichmentContext = EnrichmentContext.Get(args.Context, args.Arguments, args.Outcome);
AddCommonTags(args, source, enrichmentContext);
enrichmentContext.Tags.Add(new(ResilienceTelemetryTags.AttemptNumber, executionAttempt.Attempt.AsBoxedInt()));
enrichmentContext.Tags.Add(new(ResilienceTelemetryTags.AttemptNumber, executionAttempt.AttemptNumber.AsBoxedInt()));
enrichmentContext.Tags.Add(new(ResilienceTelemetryTags.AttemptHandled, executionAttempt.Handled.AsBoxedBool()));
EnrichmentUtil.Enrich(enrichmentContext, _enrichers);
AttemptDuration.Record(executionAttempt.ExecutionTime.TotalMilliseconds, enrichmentContext.TagsSpan);
Expand Down Expand Up @@ -142,7 +142,7 @@ private void LogEvent(TelemetryEventArguments args)
args.Context.OperationKey,
result,
executionAttempt.Handled,
executionAttempt.Attempt,
executionAttempt.AttemptNumber,
executionAttempt.ExecutionTime.TotalMilliseconds,
args.Outcome?.Exception);
}
Expand Down
Loading