forked from uber-common/cadence-samples
-
Notifications
You must be signed in to change notification settings - Fork 4
/
helloworld_workflow.go
53 lines (43 loc) · 1.29 KB
/
helloworld_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
51
52
53
package main
import (
"context"
"time"
"go.uber.org/cadence/activity"
"go.uber.org/cadence/workflow"
"go.uber.org/zap"
)
/**
* This is the hello world workflow sample.
*/
// ApplicationName is the task list for this sample
const ApplicationName = "helloWorldGroup"
// This is registration process where you register all your workflows
// and activity function handlers.
func init() {
workflow.Register(Workflow)
activity.Register(helloworldActivity)
}
// Workflow workflow decider
func Workflow(ctx workflow.Context, name string) error {
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: time.Minute,
StartToCloseTimeout: time.Minute,
HeartbeatTimeout: time.Second * 20,
}
ctx = workflow.WithActivityOptions(ctx, ao)
logger := workflow.GetLogger(ctx)
logger.Info("helloworld workflow started")
var helloworldResult string
err := workflow.ExecuteActivity(ctx, helloworldActivity, name).Get(ctx, &helloworldResult)
if err != nil {
logger.Error("Activity failed.", zap.Error(err))
return err
}
logger.Info("Workflow completed.", zap.String("Result", helloworldResult))
return nil
}
func helloworldActivity(ctx context.Context, name string) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("helloworld activity started")
return "Hello " + name + "!", nil
}