I have a Durable Function, with the rough outline as shown in the code block below. If I end up in the else section, it is because of a functional issue (in this case, because I don't have authentication details cached). And I would like to "self-terminate" the current instance of my orchestration. I can do this by throwing an exception, but I would like to find a cleaner way (if there is) to terminate the active instance with a friendly message, indicating the reason for the Termination.
Is this possible, and if yes, how?
[FunctionName(nameof(UserHistorySyncWorkflow))]
public async Task<List<Match>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext orchestrationContext, ILogger logger)
{
if(CanConnect())
{
// Call Activity function and return results
}
else
{
// How to gracefully Terminate here?
}
}
You just simply return from the else block. It will terminate gracefully. But status will be 'completed', custom status is not possible. You can log a message for the reason.
If you want to mark as 'failed', just throw exception. I don't see any problem in that.