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

[Docs] Add diagram about hedging's context and callbacks #1751

Merged
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
39 changes: 39 additions & 0 deletions docs/strategies/hedging.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,45 @@ Some insights about the hedging callback behavior in relation to hedging context
> [!NOTE]
> The hedging strategy ensures that both `ActionGenerator` and `OnHedging` are never executed concurrently. Any modifications to the contexts are thread-safe in these callbacks.

### Sequence diagram about contexts and callbacks

For the sake of conciseness the `Caller` is not depicted on the diagram.

```mermaid
sequenceDiagram
autonumber
participant P as Pipeline
participant H as Hedging
participant AG as ActionGenerator
participant OH as OnHedging
participant UC as UserCallback
participant HUC as HedgedUserCallback

P->>H: Calls ExecuteCore <br/>with Primary Context
H-->>H: Deep clones <br/>Primary Context

H->>+UC: Invokes <br/>with Action Context
UC-->>UC: Processes <br/>+ Modifies Context
UC->>-H: Fails

H-->>H: Deep clones <br/>Primary Context
H->>+AG: Invokes <br/>with both Contexts
AG-->>AG: Executes callback <br/>+ Modifies Primary <br/> and / or Action Context
AG->>-H: Returns factory

H->>+OH: Invokes <br/>with both Contexts
OH-->>OH: Executes callback <br/>+ Modifies Primary <br/> and / or Action Context
OH->>-H: Finishes

H-->>H: Invokes factory
H->>+HUC: Invokes <br/>with Action Context
HUC-->>HUC: Processes <br/>+ Modifies Context
HUC->>-H: Fails

H-->>H: Merges Action Context <br/>onto Primary Context
H->>P: Propagates failure <br/>with Primary Context
```

## Action generator

The hedging options include an `ActionGenerator` property, allowing you to customize the actions executed during hedging. By default, the `ActionGenerator` returns the original callback passed to the strategy. The original callback also includes any logic introduced by subsequent resilience strategies. For more advanced scenarios, the `ActionGenerator` can be used to return entirely new hedged actions, as demonstrated in the example below:
Expand Down