-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkflow.go
More file actions
47 lines (37 loc) · 1005 Bytes
/
workflow.go
File metadata and controls
47 lines (37 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package firstfailure
import (
"time"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/workflow"
)
type OrderInfo struct {
// ...
}
func Workflow(ctx workflow.Context, order OrderInfo) error {
retrypolicy := &temporal.RetryPolicy{
InitialInterval: time.Second,
BackoffCoefficient: 2.0,
MaximumInterval: time.Second * 120,
MaximumAttempts: 50,
NonRetryableErrorTypes: []string{"InsufficientFundsError", "AuthFailure"},
}
activityoptions := workflow.ActivityOptions{
RetryPolicy: retrypolicy,
StartToCloseTimeout: 1 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, activityoptions)
var a *Activities
err := workflow.ExecuteActivity(ctx, a.CheckInventory, order).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx, a.Charge, order).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx, a.FulfillOrder, order).Get(ctx, nil)
if err != nil {
return err
}
return nil
}