I have a workflow with multiple activities. I want to update the context of the workflow with some values (flags) in the first activity and I want to access these flags in the subsequent activities in the same workflow without passing them as parameters. The values fetched should be local to the workflow run, coz different workflow runs of the same workflow type will have different flag values.
Could you please suggest a way forward for me? Thanks.
Just to add, one thing to look into into could be sessions api with Go SDK to assure that multiple activities are executed on the same worker process / host, see file processing sample .
This would allow you for example to have one activity write a result to file system / local store / memory of that worker host and know it will be accessible to the rest of activities that run on the same host, just idea.
Thanks dor the replies.
The reason why I don’t want to pass them to the activities is that it’s messy. There’s a lot of business logic code and I want to try and separate this.
I was trying to add the flags to the workflow context and access them in the activity context. No success.
I’ll try the file sharing method that you have suggested.
Thanks for the response mate. My question is would updating the context in one workflow affect the values in other contexts? In the examples I referred for context propagators, values are passed from the worker to workflow to activity via context propagators. What I want is an activity to fetch the flags and other activities to use the flags within the same workflow.
You can implement a context propagator to propagate value of “flags” key. Then the first activity would load the flags and then call context.WithValue(ctx, "flags", flags). After that, all activities are going to have this value propagated to their contexts.