-
Couldn't load subscription status.
- Fork 225
Add retry handler support #1412
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
12 commits
Select commit
Hold shift + click to select a range
ef5d574
Add retry handler support
TheForbiddenAi dbe95c8
Wrap DurableTask objects
TheForbiddenAi 5e47afb
Rename method
TheForbiddenAi d1dc8f7
Add isNonRetriable field to WorkflowTaskFailureDetails
TheForbiddenAi 8e111ee
Add unit test
TheForbiddenAi 62c7554
Removed duplicate WorkflowFailureDetails class
TheForbiddenAi 83b0f2f
Removed unneeded when statements in retry policy unit test
TheForbiddenAi ee84d8a
Add unit test to test both RetryPolicy and RetryHandler
TheForbiddenAi 1ec646a
Merge branch 'master' into master
siri-varma 80deb0e
Create toRetryPolicy method
TheForbiddenAi 73be8f2
Merge branch 'master' of https://github.com/TheForbiddenAi/java-sdk
TheForbiddenAi a317fc8
Merge branch 'master' into master
cicoyle 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
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
88 changes: 88 additions & 0 deletions
88
sdk-workflows/src/main/java/io/dapr/workflows/WorkflowTaskRetryContext.java
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,88 @@ | ||
| /* | ||
| * Copyright 2025 The Dapr Authors | ||
| * 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. | ||
| */ | ||
|
|
||
| package io.dapr.workflows; | ||
|
|
||
| import io.dapr.workflows.client.WorkflowFailureDetails; | ||
| import io.dapr.workflows.runtime.DefaultWorkflowContext; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| public class WorkflowTaskRetryContext { | ||
|
|
||
| private final DefaultWorkflowContext workflowContext; | ||
| private final int lastAttemptNumber; | ||
| private final WorkflowFailureDetails lastFailure; | ||
| private final Duration totalRetryTime; | ||
|
|
||
| /** | ||
| * Constructor for WorkflowTaskRetryContext. | ||
| * | ||
| * @param workflowContext The workflow context | ||
| * @param lastAttemptNumber The number of the previous attempt | ||
| * @param lastFailure The failure details from the most recent failure | ||
| * @param totalRetryTime The amount of time spent retrying | ||
| */ | ||
| public WorkflowTaskRetryContext( | ||
| DefaultWorkflowContext workflowContext, | ||
| int lastAttemptNumber, | ||
| WorkflowFailureDetails lastFailure, | ||
| Duration totalRetryTime) { | ||
| this.workflowContext = workflowContext; | ||
| this.lastAttemptNumber = lastAttemptNumber; | ||
| this.lastFailure = lastFailure; | ||
| this.totalRetryTime = totalRetryTime; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the context of the current workflow. | ||
| * | ||
| * <p>The workflow context can be used in retry handlers to schedule timers (via the | ||
| * {@link DefaultWorkflowContext#createTimer} methods) for implementing delays between retries. It can also be | ||
| * used to implement time-based retry logic by using the {@link DefaultWorkflowContext#getCurrentInstant} method. | ||
| * | ||
| * @return the context of the parent workflow | ||
| */ | ||
| public DefaultWorkflowContext getWorkflowContext() { | ||
| return this.workflowContext; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the details of the previous task failure, including the exception type, message, and callstack. | ||
| * | ||
| * @return the details of the previous task failure | ||
| */ | ||
| public WorkflowFailureDetails getLastFailure() { | ||
| return this.lastFailure; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the previous retry attempt number. This number starts at 1 and increments each time the retry handler | ||
| * is invoked for a particular task failure. | ||
| * | ||
| * @return the previous retry attempt number | ||
| */ | ||
| public int getLastAttemptNumber() { | ||
| return this.lastAttemptNumber; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the total amount of time spent in a retry loop for the current task. | ||
| * | ||
| * @return the total amount of time spent in a retry loop for the current task | ||
| */ | ||
| public Duration getTotalRetryTime() { | ||
| return this.totalRetryTime; | ||
| } | ||
|
|
||
| } | ||
26 changes: 26 additions & 0 deletions
26
sdk-workflows/src/main/java/io/dapr/workflows/WorkflowTaskRetryHandler.java
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,26 @@ | ||
| /* | ||
| * Copyright 2025 The Dapr Authors | ||
| * 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. | ||
| */ | ||
|
|
||
| package io.dapr.workflows; | ||
|
|
||
| public interface WorkflowTaskRetryHandler { | ||
|
|
||
| /** | ||
| * Invokes retry handler logic. Return value indicates whether to continue retrying. | ||
| * | ||
| * @param retryContext The context of the retry | ||
| * @return {@code true} to continue retrying or {@code false} to stop retrying. | ||
| */ | ||
| boolean handle(WorkflowTaskRetryContext retryContext); | ||
|
|
||
| } |
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
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.