Fail Workflow form UpdateMethod

Hello,
I have a workflow that represents an object lifecycle. During the creation of my object, I am starting the workflow and triggering an update method to persist the object in the DB. If the activity calling the DB fails, I would like to fail the workflow.
I tried throwing a temporal failure and a normal exception, both did not to workflow failure. I know I can use WorkflowImplementationOptions.setFailWorkflowExceptionTypes to fail the workflow on certain exceptions, but I am using temporal-spring-boot-starter-alpha dependency to automatically register my workers. Is there another way to fail a workflow on a certain exception in this case?

Hi @Bilal_Fares

I don’t think exceptions thrown from update method will fail the workflow execution. Please see samples-java/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java at 30c03550420fe596dc0065d2d17e05bc2003dbec · temporalio/samples-java · GitHub

I think you can set a flag in your updateMethod, and in workflow code have something like

      if(failWorkflow){
        throw ApplicationFailure.newFailure("failing workflow", "myType");
      }

I am starting the workflow and triggering an update method to persist the object in the DB. If the activity calling the DB fails, I would like to fail the workflow.

Have you considered activity retries instead of failing the workflow?

Regards,
Antonio

Hi @antonio.perez
The activity is configured to retry a couple of times. I want to fail the workflow in case the retries also failed maybe due to a database outage. I have implemented it the way you mentioned above but was trying to find another way through which I can fail the workflow from an UpdateMethod directly.

You can track the relevant issue here: Add ability to complete workflow from any line · Issue #87 · temporalio/sdk-java · GitHub

2 Likes