1

We have a flow where if some actions are not done by a certain time period, we want to fail the workflow, to use alarming mechanisms.

For failing the workflow, I was initially thinking of just returning an exception from the code. But after reading sources online, it seems like the exception in decider flow will not let the host return the result and some other host will just pick the pending decision task after some time.

Wanted to know if there's a programmatic way to terminate the workflow in between via workflow code and marking the SWF workflow execution as failed.

voldegaur
  • 194
  • 2
  • 12

1 Answers1

1

To fail a workflow using the Flow Framework throw an Exception or its subclass from the workflow code.

Don't throw an Error from the workflow code. This indeed is going to fail a decision task which will lead to the workflow getting blocked in a retry loop.

Maxim Fateev
  • 6,458
  • 3
  • 20
  • 35
  • hi Maxim, how can we unit test the workflow for this exception. I am not getting exception on workflow invocation in unit tests. it is somehow converting exception in Promise – voldegaur Oct 10 '21 at 22:47
  • I don't remember. I believe the unit testing framework uses a different code path, so error handling, in this case, can look very different. In temporal.io I took a different approach and unit testing uses an in-memory version of the service to ensure similar experience between production and unit tests. – Maxim Fateev Oct 11 '21 at 01:52