Dynamic action workflows pattern


#1

@nmaludy@shu discussed in the #community channel how to write a workflow that accepts an action and arguments to execute. I’m writing it up here so it’s not lost. This pattern works with Orquesta only.

nmaludy [1:21 PM] so, you could implement an existing StackStorm concurrency policy with concurrency: 1 in a single shu.business_logic workflow… this workflow can accept another workflow’s name as input… then one of your tasks can call that workflow dynamically using Orquesta

shu [1:24 PM]
Idea 1: Write wrapping workflow. And apply policy to that wrapping workflow. Minus: we need to update wrapping workflow when we add more workflows to get policed (This is because there is no way to dynamically decide which workflow to run inside workflow)

shu [1:34 PM] @nmaludy you are savior. THIS WORKS

$ cat dynamic_workflow.meta.yaml

---
enabled: true
name: dynamic_workflow
runner_type: orquesta
entry_point: workflows/dynamic_workflow.yaml
parameters:
  workflow_name:
    type: string
    required: true
    default: core.noop
  workflow_input:
    type: object
    required: true

$ cat workflows/dynamic_workflow.yaml

version: 1.0

input:
  - workflow_name
  - workflow_input

output:
  - workflow_result: "{{ ctx().workflow_result }}"

tasks:
  invoke_workflow:
    action: "{{ ctx().workflow_name }}"
    input: "{{ ctx().workflow_input }}"
    next:
      - publish:
          - workflow_result: "{{ result() }}"

(W Chan) #2

This has been added to our docs Added documentation about the dynamic execution pattern by nmaludy · Pull Request #134 · StackStorm/orquesta · GitHub.