Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ctxpropagation/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
)

// @@@SNIPSTART samples-go-ctx-propagation-activity
func SampleActivity(ctx context.Context) (*Values, error) {
if val := ctx.Value(PropagateKey); val != nil {
vals := val.(Values)
return &vals, nil
}
return nil, nil
}
// @@@SNIPEND
2 changes: 2 additions & 0 deletions ctxpropagation/propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go.temporal.io/sdk/workflow"
)

// @@@SNIPSTART samples-go-ctx-propagation-propagator
type (
// contextKey is an unexported type used as key for items stored in the
// Context object
Expand Down Expand Up @@ -69,6 +70,7 @@ func (s *propagator) Extract(ctx context.Context, reader workflow.HeaderReader)

return ctx, nil
}
// @@@SNIPEND

// ExtractToWorkflow extracts values from headers and puts them into context
func (s *propagator) ExtractToWorkflow(ctx workflow.Context, reader workflow.HeaderReader) (workflow.Context, error) {
Expand Down
2 changes: 2 additions & 0 deletions ctxpropagation/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
log.Fatalf("Failed creating interceptor: %v", err)
}

// @@@SNIPSTART samples-go-ctx-propagation-starter
// The client is a heavyweight object that should be created once per process.
c, err := client.Dial(client.Options{
HostPort: client.DefaultHostPort,
Expand All @@ -45,6 +46,7 @@ func main() {
ctx = context.WithValue(ctx, ctxpropagation.PropagateKey, &ctxpropagation.Values{Key: "test", Value: "tested"})

we, err := c.ExecuteWorkflow(ctx, workflowOptions, ctxpropagation.CtxPropWorkflow)
// @@@SNIPEND
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
Expand Down
2 changes: 2 additions & 0 deletions ctxpropagation/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go.temporal.io/sdk/workflow"
)

// @@@SNIPSTART samples-go-ctx-propagation-workflow
// CtxPropWorkflow workflow definition
func CtxPropWorkflow(ctx workflow.Context) (err error) {
ao := workflow.ActivityOptions{
Expand All @@ -27,3 +28,4 @@ func CtxPropWorkflow(ctx workflow.Context) (err error) {
workflow.GetLogger(ctx).Info("Workflow completed.")
return nil
}
// @@@SNIPEND
Loading