-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathworkflow.go
46 lines (38 loc) · 1.22 KB
/
workflow.go
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
package branch
import (
"fmt"
"time"
"go.temporal.io/sdk/workflow"
)
// @@@SNIPSTART samples-go-branch-workflow-definition
// SampleBranchWorkflow is a Temporal Workflow Definition
// This Workflow Definition shows how to call multiple Activities in parallel.
// The number of branches is controlled by a passed in parameter.
func SampleBranchWorkflow(ctx workflow.Context, totalBranches int) (result []string, err error) {
logger := workflow.GetLogger(ctx)
logger.Info("SampleBranchWorkflow begin")
ao := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, ao)
var futures []workflow.Future
for i := 1; i <= totalBranches; i++ {
activityInput := fmt.Sprintf("branch %d of %d.", i, totalBranches)
future := workflow.ExecuteActivity(ctx, SampleActivity, activityInput)
futures = append(futures, future)
}
logger.Info("Activities started")
// accumulate results
for _, future := range futures {
var singleResult string
err = future.Get(ctx, &singleResult)
logger.Info("Activity returned with result", "resutl", singleResult)
if err != nil {
return
}
result = append(result, singleResult)
}
logger.Info("SampleBranchWorkflow end")
return
}
// @@@SNIPEND