From 6a898f82b2d2f1d8f8e0eef5711faf1b5f17afb4 Mon Sep 17 00:00:00 2001 From: Jakob Haahr Taankvist Date: Tue, 3 Dec 2024 15:26:14 +0100 Subject: [PATCH] Bug in retry testing --- .../recipes/helloworld/helloworld_workflow.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/samples/recipes/helloworld/helloworld_workflow.go b/cmd/samples/recipes/helloworld/helloworld_workflow.go index 94cd605..1fc887b 100644 --- a/cmd/samples/recipes/helloworld/helloworld_workflow.go +++ b/cmd/samples/recipes/helloworld/helloworld_workflow.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "time" "go.uber.org/cadence/activity" @@ -20,10 +21,20 @@ const helloWorldWorkflowName = "helloWorldWorkflow" // helloWorkflow workflow decider func helloWorldWorkflow(ctx workflow.Context, name string) error { + retry := workflow.RetryPolicy{ + InitialInterval: time.Second, + BackoffCoefficient: 0, + MaximumInterval: 0, + ExpirationInterval: 0, + MaximumAttempts: 1, + NonRetriableErrorReasons: nil, + } + ao := workflow.ActivityOptions{ ScheduleToStartTimeout: time.Minute, StartToCloseTimeout: time.Minute, HeartbeatTimeout: time.Second * 20, + RetryPolicy: &retry, } ctx = workflow.WithActivityOptions(ctx, ao) @@ -58,6 +69,12 @@ func helloWorldWorkflow(ctx workflow.Context, name string) error { } func helloWorldActivity(ctx context.Context, name string) (string, error) { + fmt.Printf("Hello %s!\n", name) + fmt.Printf("Attempt %v!\n", activity.GetInfo(ctx).Attempt) + if activity.GetInfo(ctx).Attempt == 0 { + return "", fmt.Errorf("retryable error") + } + logger := activity.GetLogger(ctx) logger.Info("helloworld activity started") return "Hello " + name + "!", nil