Hi
We are planning to implement some cleanup when a workflow is failed(not retriable) and when the workflow is completed successfully. We are failing the workflow for any Application exceptions.
WorkflowImplementationOptions wfio = WorkflowImplementationOptions.newBuilder()
.setFailWorkflowExceptionTypes(Throwable.class)
.build();
Workflow.execute(){
try {
result = compuetResult(flowInput);
cleanUpWorkflow(...);
}
catch(TemporalFailure tEx) {
temporalException = tEx;
Throwable causeEx = tEx.getCause();
boolean applicationFailure = false;
while(causeEx != null){
if(causeEx instanceof ApplicationFailure){
ApplicationFailure appEx = (ApplicationFailure)causeEx;
applicationFailure = true;
}
causeEx = causeEx.getCause();
}
if(applicationFailure) {
cleanUpWorkflow(...);
}
}
catch (MyCustomException) {
cleanUpWorkflow(...);
}
}
When workflows throw WorkflowTaskTimeout it goes to catch(TemporalFailure tEx) block and the workflow is replayed, so i had to add
if(applicationFailure) {
cleanUpWorkflow(...);
}
I want to know if there is any better way, I mean can we know if an exception triggers replay or failure of workflow based on that i can trigger cleanup.