Dynamic workflow registration

Following the dynamic sample from go-samples, we can see that activities can be registered by providing a struct with public method receivers:

w.RegisterActivity(&dynamic.Activities{})

Can something similar be done for registering workflows?

What are the options for registering workflows?

What are you trying to achieve?

I have plenty of workflows that share a lot of functionality; same signal handler, same query methods, etc. I’m looking to create a “base” workflow that can be extended so I can avoid all the boilerplate code per workflow.

The idea was to have a base workflow that includes all the above functionality, but then pass it function handlers so it can delegate the signal receivers. This doesn’t seem to be possible since function pointers and interfaces cannot be passed in as arguments.

Can you do the same from the workflow function? Something like:

func MyWorkflow(ctx workflow.Context) error {
    w :=  &CommonWorkflow{
       // whatever
    }
    w.execute(ctx)
}

That’s essentially what I ended up with. A “binding” function for each workflow that internally starts the base workflow with specific state+behavior.

This should work for me actually. I don’t think anything else is needed at this time.

Thanks.

2 Likes