-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathworkflow.go
More file actions
31 lines (26 loc) · 935 Bytes
/
workflow.go
File metadata and controls
31 lines (26 loc) · 935 Bytes
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
package ctxpropagation
import (
"time"
"go.temporal.io/sdk/workflow"
)
// @@@SNIPSTART samples-go-ctx-propagation-workflow
// CtxPropWorkflow workflow definition
func CtxPropWorkflow(ctx workflow.Context) (err error) {
ao := workflow.ActivityOptions{
StartToCloseTimeout: 2 * time.Second, // such a short timeout to make sample fail over very fast
}
ctx = workflow.WithActivityOptions(ctx, ao)
if val := ctx.Value(PropagateKey); val != nil {
vals := val.(Values)
workflow.GetLogger(ctx).Info("custom context propagated to workflow", vals.Key, vals.Value)
}
var values Values
if err = workflow.ExecuteActivity(ctx, SampleActivity).Get(ctx, &values); err != nil {
workflow.GetLogger(ctx).Error("Workflow failed.", "Error", err)
return err
}
workflow.GetLogger(ctx).Info("context propagated to activity", values.Key, values.Value)
workflow.GetLogger(ctx).Info("Workflow completed.")
return nil
}
// @@@SNIPEND