Workflow withItems fails if 1 of the actions fail
Discussed in https://github.com/StackStorm/st2/discussions/5970
Originally posted by glafkosch May 1, 2023 I am making dynamically generated worker requests with make_worker_requests task and passing those to another task run_linked_workers which runs for each item the action tf.run-worker-and-store-result.
The run_linked_workers task runs various worker checks for my project such as sslcheck, webcheck, dbcheck, etc. Everything works well if all return success but if even one check fails which is normal to fail in my case then the whole task fail.
As per documentation: "All action executions must complete successfully for the task to reach a succeeded state. If one or more action executions fail, then the task will result in a failed state." ref: https://docs.stackstorm.com/orquesta/languages/orquesta.html#with-items-model
Is there any solution to solve this? Maybe is possible to introduce an additional variable to withItems if it should fail or succeed?
make_worker_requests: action: tf.make_worker_requests input: target: <% ctx().target %> target_type: <% ctx().target_type %> services: "{{ ctx().services }}" step: <% ctx().step %> scan_id: <% ctx().scan_id %> next: - when: <% succeeded() %> publish: - portscan_linked_worker_requests: <% result().result %> do: run_linked_workers - when: <% failed() %> publish: - errors: <% ctx().errors + [dict(summary=>"Unable to make worker requests.", detail=>result())] %> do: - fail
run_linked_workers: with: items: <% ctx().portscan_linked_worker_requests %> action: tf.run-worker-and-store-result input: worker_request: <% item() %> next: - when: <% succeeded() %> publish: - lwo: <% result() %> - when: <% failed() %> publish: - errors: <% ctx().errors + [dict(summary=>"Unable to run linked workers.", detail=>result())] %> do: - fail
if you want the workflow to continue even if a task fails, you can instruct the workflow to do so, with specifying the task to do next if the task fails, so you can change: do: run_linked_workers
- when: <% failed() %> publish:
- errors: <% ctx().errors + [dict(summary=>"Unable to make worker requests.", detail=>result())] %> do:
- fail
to: do: run_linked_workers
- when: <% failed() %> publish:
- errors: <% ctx().errors + [dict(summary=>"Unable to make worker requests.", detail=>result())] %> do:
- fail
- noop
this should instruct the workflow engine to continue execution in a failed state, so you'll have to handle the failure down the line (as the workflow will report failed)