-
Notifications
You must be signed in to change notification settings - Fork 204
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
Add retry mechanic to worker-specific-task-queue sample #383
Merged
yuandrew
merged 4 commits into
temporalio:main
from
yuandrew:worker-specific-task-queue-retries
Jan 28, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2608269
Add in a retry mechanic
yuandrew 8647e84
Merge branch 'main' into worker-specific-task-queue-retries
yuandrew 12a9668
Add tests demonstrating retry/failure
yuandrew 978f60c
Merge remote-tracking branch 'origin/worker-specific-task-queue-retri…
yuandrew 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 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package worker_specific_task_queues | ||
|
||
import ( | ||
"go.temporal.io/sdk/temporal" | ||
"path/filepath" | ||
"time" | ||
|
||
|
@@ -11,8 +12,25 @@ import ( | |
// FileProcessingWorkflow is a workflow that uses Worker-specific Task Queues to run multiple Activities on a consistent | ||
// host. | ||
func FileProcessingWorkflow(ctx workflow.Context) (err error) { | ||
// When using a worker-specific task queue, if a failure occurs, we want to retry all of the worker-specific | ||
// logic, so wrap all the logic here in a loop. | ||
for attempt := range 5 { | ||
if err = processFile(ctx); err == nil { | ||
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. Arguably one might only retry on schedule to close timeout, but this is probably fine too. |
||
workflow.GetLogger(ctx).Info("Workflow completed.") | ||
return | ||
} | ||
workflow.GetLogger(ctx).Error("Attempt failed, trying on new worker", attempt+1) | ||
} | ||
workflow.GetLogger(ctx).Error("Workflow failed after multiple retries.", "Error", err.Error()) | ||
return | ||
} | ||
|
||
func processFile(ctx workflow.Context) (err error) { | ||
ao := workflow.ActivityOptions{ | ||
StartToCloseTimeout: time.Minute, | ||
RetryPolicy: &temporal.RetryPolicy{ | ||
MaximumAttempts: 1, | ||
}, | ||
} | ||
ctx = workflow.WithActivityOptions(ctx, ao) | ||
var WorkerSpecificTaskQueue string | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can add a unit test to show the retry working? Not blocking but would be nice to show in a unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, added!