[英]How to terminate a Durable orchestration with custom status in Azure Durable Functions
I have a Durable Function, with the rough outline as shown in the code block below.我有一个 Durable Function,其粗略轮廓如下面的代码块所示。 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).如果我最终进入 else 部分,那是因为功能问题(在这种情况下,因为我没有缓存身份验证详细信息)。 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.您只需从 else 块返回即可。 It will terminate gracefully.它将优雅地终止。 But status will be 'completed', custom status is not possible.但是状态将是“已完成”,自定义状态是不可能的。 You can log a message for the reason.您可以记录一条消息以了解原因。
[FunctionName(nameof(UserHistorySyncWorkflow))]
public async Task<List<Match>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext orchestrationContext, ILogger logger)
{
if(CanConnect())
{
// Call Activity function and return results
}
else
{
// Gracefully terminating.
logger.LogInformation("Exiting since nothing to do!");
return null;
}
}
If you want to mark as 'failed', just throw exception.如果您想标记为“失败”,只需抛出异常。 I don't see any problem in that.我看不出有什么问题。
[FunctionName(nameof(UserHistorySyncWorkflow))]
public async Task<List<Match>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext orchestrationContext, ILogger logger)
{
if(CanConnect())
{
// Call Activity function and return results
}
else
{
throw new FunctionException("Exiting since nothing to do!");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.