How to create workflows dynamically in cadence

674 Views Asked by At

Each workflow should be implemented in a separate workflow class?

Is it recommended to implement a generic workflow class where we will call activities and fire timers using the argument which passed to the workflow?

In our use case, we will be creating workflows from UI and it will be created by the end-user. So we cannot define our workflows initially.

Is it recommended approach?

1

There are 1 best solutions below

3
On

It’s not recommended.

Even though it is still possible if you have to create and register workflow class dynamically using anonymous class. But it will be very difficult to maintain and debug. For example, registering a workflow requires a unique workflow type name, and also it’s required to register back the exact same workflow after worker restarts. Etc.

What you describe is very common use cases in Cadence. And this is also the power of Cadence over other DSL workflow engine. What you need to do is implement a workflow in a way that takes in dynamic input parameters, and decides the behavior on the input. It’s essentially exactly same as what you want to do with dynamic workflow class.