forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.go
77 lines (59 loc) · 1.88 KB
/
helloworld.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package helloworld
import (
"context"
"time"
ansibler "github.com/febrianrendak/go-ansible"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/workflow"
// TODO(cretz): Remove when tagged
_ "go.temporal.io/sdk/contrib/tools/workflowcheck/determinism"
)
// Workflow is a Hello World workflow definition.
func Workflow(ctx workflow.Context, name string) (string, error) {
ao := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, ao)
logger := workflow.GetLogger(ctx)
logger.Info("HelloWorld workflow started", "name", name)
var result string
err := workflow.ExecuteActivity(ctx, Activity, name).Get(ctx, &result)
if err != nil {
logger.Error("Activity failed.", "Error", err)
return "", err
}
logger.Info("HelloWorld workflow completed.", "result", result)
err = workflow.ExecuteActivity(ctx, Activity2, name).Get(ctx, &result)
if err != nil {
logger.Error("Activity failed.", "Error", err)
return "", err
}
logger.Info("HelloWorld workflow completed.", "result", result)
return result, nil
}
func Activity(ctx context.Context, name string) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("Activity", "name", name)
return "Hello " + name + "!", nil
}
func Activity2(ctx context.Context, name string) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("Activity", "name", name)
ansiblePlaybookConnectionOptions := &ansibler.AnsiblePlaybookConnectionOptions{
Connection: "local",
}
ansiblePlaybookOptions := &ansibler.AnsiblePlaybookOptions{
Inventory: "127.0.0.1,",
}
playbook := &ansibler.AnsiblePlaybookCmd{
Playbook: "site.yml",
ConnectionOptions: ansiblePlaybookConnectionOptions,
Options: ansiblePlaybookOptions,
ExecPrefix: "Go-ansible example",
}
err := playbook.Run()
if err != nil {
panic(err)
}
return "Hello " + "dummy" + "!", nil
}