-
Notifications
You must be signed in to change notification settings - Fork 202
/
workflow.go
50 lines (41 loc) · 1.39 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
47
48
49
50
package greetings
import (
"time"
"go.temporal.io/sdk/workflow"
)
// GreetingSample workflow definition.
// This greetings sample workflow executes 3 activities in sequential.
// It gets greeting and name from 2 different activities,
// and then pass greeting and name as input to a 3rd activity to generate final greetings.
func GreetingSample(ctx workflow.Context) (string, error) {
logger := workflow.GetLogger(ctx)
ao := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, ao)
// @@@SNIPSTART samples-go-dependency-sharing-workflow
var a *Activities // use a nil struct pointer to call activities that are part of a structure
var greetResult string
err := workflow.ExecuteActivity(ctx, a.GetGreeting).Get(ctx, &greetResult)
if err != nil {
logger.Error("Get greeting failed.", "Error", err)
return "", err
}
// @@@SNIPEND
// Get Name.
var nameResult string
err = workflow.ExecuteActivity(ctx, a.GetName).Get(ctx, &nameResult)
if err != nil {
logger.Error("Get name failed.", "Error", err)
return "", err
}
// Say Greeting.
var sayResult string
err = workflow.ExecuteActivity(ctx, a.SayGreeting, greetResult, nameResult).Get(ctx, &sayResult)
if err != nil {
logger.Error("Marshalling failed with error.", "Error", err)
return "", err
}
logger.Info("GreetingSample completed.", "Result", sayResult)
return sayResult, nil
}