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

Fix the behavior of OnHedging event #1625

Merged
merged 7 commits into from
Sep 26, 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/TaskExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ private async Task HandleOnHedgingAsync(ResilienceContext primaryContext, int at

_telemetry.Report(new(ResilienceEventSeverity.Warning, HedgingConstants.OnHedgingEventName), Context, args);

if (_handler.OnHedging is not null)
if (_handler.OnHedging is { } onHedging)
{
await _handler.OnHedging(args).ConfigureAwait(Context.ContinueOnCapturedContext);
await onHedging(args).ConfigureAwait(Context.ContinueOnCapturedContext);
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ namespace Polly.Hedging;
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <remarks>
/// The <see cref="PrimaryContext"/> represents the context that was received by the hedging strategy and used to execute the primary action.
/// To prevent race conditions, hedging strategy then clones the primary context into <see cref="ActionContext"/> and uses it to execute the hedged action.
/// Every hedged action gets its own context that is cloned from primary.
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// <para>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </para>
/// </remarks>
public readonly struct HedgingActionGeneratorArguments<TResult>
{
/// <summary>
/// Initializes a new instance of the <see cref="HedgingActionGeneratorArguments{TResult}"/> struct.
/// </summary>
/// <param name="primaryContext">The primary resilience context.</param>
/// <param name="actionContext">
/// The context that will be passed to action generated by <see cref="HedgingStrategyOptions{TResult}.ActionGenerator"/>.
/// .</param>
/// <param name="primaryContext">The primary context received by hedging strategy.</param>
/// <param name="actionContext">The action context. cloned from the primary context.</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="primaryContext">The primary context received by hedging strategy.</param>
/// <param name="actionContext">The action context. cloned from the primary context.</param>
/// <param name="primaryContext">The primary context received by the hedging strategy.</param>
/// <param name="actionContext">The action context cloned from the primary context.</param>

/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
/// <param name="callback">The callback passed to hedging strategy.</param>
public HedgingActionGeneratorArguments(
Expand All @@ -33,12 +36,12 @@ public HedgingActionGeneratorArguments(
}

/// <summary>
/// Gets the primary resilience context.
/// Gets the primary resilience context as received by hedging strategy.
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public ResilienceContext PrimaryContext { get; }

/// <summary>
/// Gets the context that will be passed to action generated by <see cref="HedgingStrategyOptions{TResult}.ActionGenerator"/>.
/// Gets the action context that will be used for the hedged action.
/// </summary>
/// <remarks>
/// This context is cloned from <see cref="PrimaryContext"/>.
Expand Down
11 changes: 8 additions & 3 deletions src/Polly.Core/Hedging/OnHedgingArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public readonly struct OnHedgingArguments<TResult>
/// <summary>
/// Initializes a new instance of the <see cref="OnHedgingArguments{TResult}"/> struct.
/// </summary>
/// <param name="primaryContext">The outcome of the resilience operation or event.</param>
/// <param name="actionContext">The action context.</param>
/// <param name="primaryContext">The primary context received by hedging strategy.</param>
/// <param name="actionContext">The action context. cloned from the primary context.</param>
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
/// <remarks>
/// The <paramref name="primaryContext"/> represents the context that was received by the hedging strategy and used to execute the primary action.
/// To prevent race conditions, hedging strategy then clones the primary context into <paramref name="actionContext"/> and uses it to execute the hedged action.
/// Every hedged action gets its own context that is cloned from primary.
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// </remarks>
public OnHedgingArguments(ResilienceContext primaryContext, ResilienceContext actionContext, int attemptNumber)
{
PrimaryContext = primaryContext;
Expand All @@ -25,7 +30,7 @@ public OnHedgingArguments(ResilienceContext primaryContext, ResilienceContext ac
}

/// <summary>
/// Gets the primary resilience context.
/// Gets the primary resilience context as received by hedging strategy.
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public ResilienceContext PrimaryContext { get; }

Expand Down