Passing data from workflow to activity inside context

As far as I know, if I want to pass some data from workflow class to an activity class, I can use context and context propagator. In Go-samples code, so far I can only find activities that use the ctx object for logging:
image

Without using context propagator, what are the other uses of ctx inside activity?

When executing activity, we can pass multiple arguments. Currently, I create a map to pass additional variables to activity.

ExecuteActivity(ctx Context, activity interface{}, args …interface{})

If I pass the workflow context as the last argument, can I access the value from inside activity without context propagation?

From this article, Passing Context with Temporal​ | Spiral Scout Company News, it is suggested that I should not pass business data (e.g. userId) using context to activity. I don’t quite understand about this:

“the services don’t work with the context, and it is not best practice to extract some context values from the service directly. Please note, we can encapsulate it in a ContextRegistrar component under interface.”

Service refers to the activity right? We should use ContextRegistrar to access the context, but can the ContextRegistrar return the ctx value back to activity? Because I want to use it inside the activity. The addition of ContextRegistrar adds complexity to the activity implementation, is there a better and simpler way?

I guess its mostly about a ‘clean’ activity for idempotency.
Using/manipulating on a (workflow) context means you might break that rule so might get weird behavior on retries

1 Like