-
Notifications
You must be signed in to change notification settings - Fork 10
Retry Handler Support when call activity or suborchestration #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fcf15cc
feat: Enhance retry mechanism with failure handling and context
YunchuWang b05cd0f
feat: Implement advanced retry features with handleFailure predicate …
YunchuWang 157f357
feat: Implement AsyncRetryHandler and refactor retry task handling
YunchuWang 93d2af8
feat: Refactor taskType to use RetryTaskType in RetryHandlerTask and …
YunchuWang eceb158
feat: Add E2E tests for AsyncRetryHandler with activity and sub-orche…
YunchuWang 957c0b8
Merge branch 'main' into wangbill/retryhandler
YunchuWang c34b2ea
Update packages/durabletask-js/src/task/retry/retry-policy.ts
YunchuWang 8ebd6af
Update packages/durabletask-js/src/task/retry/retry-handler.ts
YunchuWang 6f5cb2f
feat: Add taskName getter to RetryTaskBase and log retry attempts in …
YunchuWang 554ba1e
Merge branch 'wangbill/retryhandler' of https://github.com/microsoft/…
YunchuWang 3e10cdb
Update packages/durabletask-js/src/task/retry/retry-policy.ts
YunchuWang 522996e
feat: Enhance retry handler functionality with orchestration context …
YunchuWang 4c4a906
Merge branch 'wangbill/retryhandler' of https://github.com/microsoft/…
YunchuWang 4293820
fix unit tests
YunchuWang 4dda8a8
fix: Preserve custom error names in failure details and adjust retry …
YunchuWang c8e8fd2
refactor: Defer exception creation in recordFailure method and adjust…
YunchuWang 7a02ceb
refactor: Remove isCancelled property from RetryContext and related t…
YunchuWang 154f118
refactor: Remove unused retry handler options and related tests
YunchuWang 39a30cc
fix: Ensure non-null handler in RetryHandlerTask constructor
YunchuWang f2d0287
feat: Enhance retry handling with support for delay in milliseconds a…
YunchuWang 47c011a
feat: Add updateAction method to RetryTaskBase and synchronize action…
YunchuWang a133620
feat: Enhance retry handler to support returning delays and add compr…
YunchuWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import * as pb from "../proto/orchestrator_service_pb"; | ||
| import { OrchestrationContext } from "./context/orchestration-context"; | ||
| import { RetryTaskBase, RetryTaskType } from "./retry-task-base"; | ||
| import { AsyncRetryHandler, RetryHandlerResult } from "./retry/retry-handler"; | ||
| import { createRetryContext } from "./retry/retry-context"; | ||
| import { TaskFailureDetails } from "./failure-details"; | ||
|
|
||
| /** | ||
| * A task that uses an AsyncRetryHandler for imperative retry control. | ||
| * | ||
| * @remarks | ||
| * Unlike RetryableTask which uses a declarative RetryPolicy, this task delegates | ||
| * all retry decisions to a user-provided handler function. The handler receives | ||
| * a RetryContext with failure details, attempt count, and elapsed time, and | ||
| * returns true to retry or false to stop. | ||
| * | ||
| * This mirrors the .NET SDK's InvokeWithCustomRetryHandler pattern, where the | ||
| * retry handler runs as orchestrator code (subject to replay). | ||
| */ | ||
| export class RetryHandlerTask<T> extends RetryTaskBase<T> { | ||
| private readonly _handler: AsyncRetryHandler; | ||
| private readonly _orchestrationContext: OrchestrationContext; | ||
|
|
||
| /** | ||
| * Creates a new RetryHandlerTask instance. | ||
| * | ||
| * @param handler - The async retry handler for imperative retry decisions | ||
| * @param orchestrationContext - The orchestration context for the current execution | ||
| * @param action - The orchestrator action associated with this task | ||
| * @param startTime - The time when the task was first scheduled | ||
| * @param taskType - The type of task (activity or sub-orchestration) | ||
| */ | ||
| constructor( | ||
| handler: AsyncRetryHandler, | ||
| orchestrationContext: OrchestrationContext, | ||
| action: pb.OrchestratorAction, | ||
| startTime: Date, | ||
| taskType: RetryTaskType, | ||
| ) { | ||
| super(action, startTime, taskType); | ||
| if (!handler) { | ||
| throw new Error("RetryHandlerTask requires a non-null handler"); | ||
| } | ||
| this._handler = handler; | ||
| this._orchestrationContext = orchestrationContext; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the async retry handler for this task. | ||
|
YunchuWang marked this conversation as resolved.
|
||
| */ | ||
| get handler(): AsyncRetryHandler { | ||
| return this._handler; | ||
| } | ||
|
|
||
| /** | ||
| * Invokes the async retry handler to determine whether to retry. | ||
| * | ||
| * @param currentTime - The current orchestration time (for deterministic replay) | ||
| * @returns A Promise that resolves to `true` to retry immediately, | ||
| * `false` to stop retrying, or a positive number indicating the | ||
| * delay in milliseconds before the next retry attempt | ||
| */ | ||
| async shouldRetry(currentTime: Date): Promise<RetryHandlerResult> { | ||
| if (!this.lastFailure) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check for non-retriable failures (e.g., activity not found) | ||
| if (this.lastFailure.getIsnonretriable()) { | ||
| return false; | ||
| } | ||
|
|
||
| const failureDetails: TaskFailureDetails = { | ||
| errorType: this.lastFailure.getErrortype() || "Error", | ||
| message: this.lastFailure.getErrormessage() || "", | ||
| stackTrace: this.lastFailure.getStacktrace()?.getValue(), | ||
| }; | ||
|
|
||
| const totalRetryTimeMs = currentTime.getTime() - this.startTime.getTime(); | ||
|
|
||
| const retryContext = createRetryContext( | ||
| this._orchestrationContext, | ||
| this.attemptCount, | ||
| failureDetails, | ||
| totalRetryTimeMs, | ||
| ); | ||
|
|
||
|
YunchuWang marked this conversation as resolved.
|
||
| return this._handler(retryContext); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.