繁体   English   中英

如何在 Azure Durable Functions 中终止具有自定义状态的 Durable 业务流程

[英]How to terminate a Durable orchestration with custom status in Azure Durable Functions

我有一个 Durable Function,其粗略轮廓如下面的代码块所示。 如果我最终进入 else 部分,那是因为功能问题(在这种情况下,因为我没有缓存身份验证详细信息)。 我想“自我终止”我的编排的当前实例。 我可以通过抛出异常来做到这一点,但我想找到一种更简洁的方法(如果有)用友好的消息终止活动实例,表明终止的原因。

这是可能的,如果是,如何?

[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?
  }
}

您只需从 else 块返回即可。 它将优雅地终止。 但是状态将是“已完成”,自定义状态是不可能的。 您可以记录一条消息以了解原因。

[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;
  }
}

在此处输入图片说明

如果您想标记为“失败”,只需抛出异常。 我看不出有什么问题。

[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM