Skip to content

Throwing OrchestratorBlockedException from finally block to handle any exception without interrupting orchestration flow #173

@SayantaBhar

Description

@SayantaBhar

We are executing no. of activities after doing some parsing and resolving dependent tasks in our orchestration function.
Now, in order to perform some important clean up job, all of the above logic needs to be inside a try-catch-finally block.
But as per documentation:
https://learn.microsoft.com/en-us/java/api/com.microsoft.durabletask.orchestratorblockedexception?view=durabletask-java-1.x

OrchestratorBlockedException is thrown when an orchestrator calls Task#await on an uncompleted task. The purpose of throwing in this way is to halt execution of the orchestrator to save the current state and commit any side effects. Catching OrchestratorBlockedException in user code could prevent the orchestration from saving state and scheduling new tasks, resulting in the orchestration getting stuck.

Hence, had to throw exception from finally block in case of OrchestratorBlockedException was thrown like the following:

try {
            // parsing
            taskOrchestrationContext.allOf(parallelTasks).await();
            // checking what all tasks' dependant tasks are complete
            taskOrchestrationContext.createTimer(Duration.ofSeconds(5)).await();
            //
} catch (Exception e) {
            // logging error
            caughtException = e;
        } finally {
            // 
            if (caughtException instanceof OrchestratorBlockedException) {
                throw caughtException;
            } else {
                // Do some important clean up job
            }
        }

Otherwise was getting stuck with following exception

Exception occurred: The orchestrator is blocked and waiting for new inputs. This Throwable should never be caught by user code.
com.microsoft.durabletask.interruption.OrchestratorBlockedException: The orchestrator is blocked and waiting for new inputs. This Throwable should never be caught by user code.

Do you see any issue with such kind of handling? Is there any better way to handle the above mentioned situation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions