Approaches to reading/parsing workflow definitions from YAML or JSON file

Hi. We want to define Workflow structures in a .yml file following some pattern that will allow us to define conditions, activity calls, branching, returns, etc. (something like this go sample) .

The goal is to code the Activities but not the workflows, which we want to recreate by parsing that .yml file .

Is there a general consense on how to translate a YAML file into a workflow definition?

Our worker registers workflows found in a directory when the Temporal container starts, and we thought that instead of doing that we could build the workflow class definition by parsing the .yml file and then make the worker register that.

I wonder if that’s too complex/hard to mantain and if a different approach would be better, like having a generic workflow that interpretes the .yml file (although I don’t like that all workflows would have this generic workflow’s name in the dashboard).

Any input or examples would be appreciated, as we are using the Ruby SDK which is not feature complete yet.

Live-building the class won’t work too well, though technically we do allow you to build the Temporalio::Workflow::Definition::Info manually and register that. It needs a class, but it can have different names and such for each. But it is less clear to manually build definitions than it may be to have a single workflow as mentioned below.

Yes, the single-workflow approach is often a clearer and is what we refer to as a “DSL workflow”. It can even define interactions like signal, query, and update handlers at runtime within the workflow. But if you must have the workflow name/type in the dashboard you can use what we call “dynamic workflows”. This is a single fall through workflow per worker that is called for every workflow name/type that is not explicitly registered. It can do the same things as the single DSL workflow, but in this case you get the workflow name/type retained.

The SDK is feature complete, but we do not have any examples for these use cases yet. For dynamic workflows, we touch on it in the README, in the rubydoc for the workflow_dynamic class method you would use, and you can see where we have a test showing the behavior.

2 Likes