forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.go
49 lines (38 loc) · 1.12 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
package encryption
import (
"context"
"time"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/workflow"
)
// Workflow is a standard workflow definition.
// Note that the Workflow and Activity don't need to care that
// their inputs/results are being encrypted/decrypted.
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("Encrypted Payloads workflow started", "name", name)
info := map[string]string{
"name": name,
}
var result string
err := workflow.ExecuteActivity(ctx, Activity, info).Get(ctx, &result)
if err != nil {
logger.Error("Activity failed.", "Error", err)
return "", err
}
logger.Info("Encrypted Payloads workflow completed.", "result", result)
return result, nil
}
func Activity(ctx context.Context, info map[string]string) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("Activity", "info", info)
name, ok := info["name"]
if !ok {
name = "someone"
}
return "Hello " + name + "!", nil
}