簡體   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