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 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
Next Next commit
Add diagram about hedging's context and callbacks
  • Loading branch information
peter-csala committed Oct 30, 2023
commit 1b60751cb27f9d559a06b3a92127320c95ffa129
40 changes: 40 additions & 0 deletions docs/strategies/hedging.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
- After the strategy has an accepted result from a hedged action, the resilience context from the action is merged back into the primary context.
- All ongoing hedged actions are cancelled and discarded. The hedging strategy awaits the propagation of cancellation.


Check failure on line 457 in docs/strategies/hedging.md

View workflow job for this annotation

GitHub Actions / publish-docs

Multiple consecutive blank lines

docs/strategies/hedging.md:457 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md012.md
### Merging action context into the primary context

After merging, the primary context contains:
Expand All @@ -471,6 +472,45 @@
> [!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 UC as UserCallback
participant HUC as HedgedUserCallback
participant OH as OnHedging

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

H->>+UC: Invokes <br/>with Primary Context
peter-csala marked this conversation as resolved.
Show resolved Hide resolved
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: Modifies Primary Context
peter-csala marked this conversation as resolved.
Show resolved Hide resolved
AG->>-H: Returns factory

H->>+OH: Invokes <br/>with both Contexts
OH-->>OH: Executes callback <br/>+ Modifies 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
Loading