-
Notifications
You must be signed in to change notification settings - Fork 329
Add poison message handling to the dispatchers #1366
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
base: main
Are you sure you want to change the base?
Changes from all commits
de244ff
8f6bf9d
ea5a36f
3ab0859
4c7665d
3bd1dc9
2e3c7c2
eecc077
f0fc35d
ea7a67f
c976817
559bb4d
68dbde9
b9a875d
8a77b40
c7d5803
b091049
868b856
d13c7b3
85ae250
7cbb931
756d592
d54925a
2657e8d
1fb9930
7f5f923
3607f36
2f4490f
1318aa6
dff3c25
573e66c
30194ec
a96de44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,12 @@ public ExecutionRewoundEvent(int eventId, string? reason) | |
| this.Reason = reason; | ||
| } | ||
|
|
||
| // Private ctor for JSON deserialization (required by some storage providers and out-of-proc executors) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but I bug I found when testing (JSON was not able to deserialize this event because it lacked a 0-arg constructor and the other constructors all had multiple parameters) |
||
| ExecutionRewoundEvent() | ||
| : base(-1) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the event type | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
| #nullable enable | ||
| namespace DurableTask.Core | ||
| { | ||
| using System.Threading.Tasks; | ||
| using DurableTask.Core.History; | ||
|
|
||
| /// <summary> | ||
| /// Categorizes why a message or work item was considered "poisoned" so that an | ||
| /// <see cref="IPoisonMessageHandler"/> can decide how to handle it without parsing human-readable strings. | ||
| /// </summary> | ||
| public enum PoisonMessageReason | ||
| { | ||
| /// <summary> | ||
| /// A message or event could not be deserialized | ||
| /// </summary> | ||
| DeserializationError, | ||
|
|
||
| /// <summary> | ||
| /// A message was dispatched for processing more than <see cref="IPoisonMessageHandler.MaxDispatchCount"/> | ||
| /// times and is therefore considered "poisoned". | ||
| /// </summary> | ||
| DispatchCount, | ||
|
|
||
| /// <summary> | ||
| /// A message or work item did not contain the orchestration instance information required to process it. | ||
| /// </summary> | ||
| MissingOrchestrationInstanceId, | ||
|
|
||
| /// <summary> | ||
| /// The orchestration runtime state reconstructed from history was invalid (for example, corrupted or | ||
| /// partially deleted history) and could not be processed. | ||
| /// </summary> | ||
| InvalidRuntimeState, | ||
|
|
||
| /// <summary> | ||
| /// The orchestration history did not contain the required <see cref="History.ExecutionStartedEvent"/> and | ||
| /// did not receive one as part of its new messages. | ||
| /// </summary> | ||
| MissingExecutionStartedEvent, | ||
|
|
||
| /// <summary> | ||
| /// A rewind request was invalid, for example because additional messages were delivered alongside the rewind | ||
| /// request to an instance attempting to rewind from a terminal state. | ||
| /// </summary> | ||
| InvalidRewindRequest, | ||
|
|
||
| /// <summary> | ||
| /// A work item contained an event whose type is not supported by the dispatcher that received it. | ||
| /// </summary> | ||
| WrongEventType, | ||
|
|
||
| /// <summary> | ||
| /// An activity work item's <see cref="History.TaskScheduledEvent"/> did not specify an activity name, so the | ||
| /// activity could not be dispatched. | ||
| /// </summary> | ||
| MissingActivityName, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Provides extensibility points for detecting and handling "poison" messages and invalid work items | ||
| /// in the task dispatchers. | ||
| /// </summary> | ||
| public interface IPoisonMessageHandler | ||
| { | ||
| /// <summary> | ||
| /// The maximum dispatch count after which a message should be considered "poisoned" if it is dispatched again. | ||
| /// </summary> | ||
| public int MaxDispatchCount { get; } | ||
|
|
||
| /// <summary> | ||
| /// Invoked to handle a poison entity message in the case that it cannot necessarily | ||
| /// be "failed" by the dispatchers, so the <see cref="IPoisonMessageHandler"/> must | ||
| /// decide what to do. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// If this method returns false, the dispatcher should fall back to the default behavior | ||
| /// followed when poison message handling is not enabled. | ||
| /// </remarks> | ||
| /// <param name="entityInstance">The entity instance the event was sent to, or null | ||
| /// if this information is not available.</param> | ||
| /// <param name="historyEvent">The "poisoned" history event.</param> | ||
| /// <param name="reason">The category describing why the event is "poisoned".</param> | ||
| /// <param name="details">A human-readable description of why the event is "poisoned".</param> | ||
| /// <returns>True if the poison message was successfully handled, otherwise false.</returns> | ||
|
sophiatev marked this conversation as resolved.
|
||
| public Task<bool> HandlePoisonEntityMessageAsync(OrchestrationInstance? entityInstance, HistoryEvent historyEvent, PoisonMessageReason reason, string details); | ||
|
|
||
| /// <summary> | ||
| /// Invoked to handle a work item that is invalid and cannot be processed at all. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// If this method returns false, the dispatcher should fall back to the default behavior | ||
| /// followed in the case of an invalid work item. | ||
| /// </remarks> | ||
| /// <param name="workItem">The work item that could not be processed.</param> | ||
| /// <param name="reason">The category describing why the work item is invalid.</param> | ||
| /// <param name="details">A human-readable description of why the work item is invalid.</param> | ||
| /// <param name="isEntity">Indicates whether the work item is for an entity.</param> | ||
| /// <returns>True if the poison message was successfully handled, otherwise false.</returns> | ||
| public Task<bool> HandleInvalidWorkItemAsync(TaskOrchestrationWorkItem workItem, PoisonMessageReason reason, string details, bool isEntity); | ||
|
|
||
| /// <summary> | ||
| /// Invoked to handle a work item that is invalid and cannot be processed at all. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// If this method returns false, the dispatcher should fall back to the default behavior | ||
| /// followed in the case of an invalid work item. | ||
| /// </remarks> | ||
| /// <param name="workItem">The work item that could not be processed.</param> | ||
| /// <param name="reason">The category describing why the work item is invalid.</param> | ||
| /// <param name="details">A human-readable description of why the work item is invalid.</param> | ||
| /// <returns>True if the poison message was successfully handled, otherwise false.</returns> | ||
| public Task<bool> HandleInvalidWorkItemAsync(TaskActivityWorkItem workItem, PoisonMessageReason reason, string details); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.