Day #4 with Cloud Workflows: jumping with switch conditions
In the previous articles about Google Cloud Workflows, we talked about how to assign variables, create expressions, and also how to jump from a step to another. It’s time to combine both aspects to understand how we can do conditional jumps, thanks to the switch instruction.
Let’s start with a first step defining a variable, whose value we’ll use in our switch condition:
Then we’re going to create our second step that will use a switch instruction, with an expression:
We define two conditions with two expressions, checking if the number is above or below 100, then we go to a different step (highValue or lowValue steps). If none of the conditions are met, we go to the end of the workflow (or we could return some value or raise some error).
We also need our two steps to go to:
And we’re done! If the number is 42, like in our case, the execution of the workflow will go through the lowValue step, and return the string saying that it’s a low value.