【问题标题】:How to check running status and stop Durable function如何检查运行状态和停止 Durable 功能
【发布时间】:2019-05-06 21:20:35
【问题描述】:

我想按需处理数百万条记录,这需要大约 2-3 小时来处理。我想去无服务器,这就是为什么尝试持久功能(第一次)。我想检查一下,我可以运行持久函数多长时间,所以我创建了 3 个函数

  1. 启动 Orchestrator 功能的 Http 函数
  2. 协调器功能
  3. 活动功能

我的 DurableFunction 正在 Application Insights 中运行并发出过去 5 天的日志,根据我的代码,它还需要 15 天才能完成。

我想知道如何手动停止 Orchestrator 功能?

我可以在 ApplicationInsights 请求表中看到数千个单次执行的条目,有没有办法检查后端运行了多少 DurableFunction?以及单次执行需要多少时间?

我可以在“DurableFunctionHubInstance”表中看到有关编排器功能的一些信息,但 MS 建议不要依赖表。

【问题讨论】:

  • 除了我在下面的回答之外,我还想建议您研究一下 Durable Functions 提供的各种模式。您在此处显示的示例是函数链接并且是顺序的,您在执行下一个函数之前等待第一个函数的完成。在您的情况下,您可以改用fan-out/fan-in pattern,这样您就可以并行调用活动函数。

标签: azure azure-durable-functions


【解决方案1】:

由于 Durable Functions 做了很多 checkpointing and replays the orchestration,正常的日志记录可能并不总是很有洞察力。

获取状态

查询编排状态的方法有多种。其中之一是通过 George Chen 提到的Azure Functions Core tools

另一种查询状态的方法是直接使用Durable Functions的HTTP API:

GET <rooturl>/runtime/webhooks/durableTask/instances?
    taskHub={taskHub}
    &connection={connectionName}
    &code={systemKey}
    &createdTimeFrom={timestamp}
    &createdTimeTo={timestamp}
    &runtimeStatus={runtimeStatus1,runtimeStatus2,...}
    &showInput=[true|false]
    &top={integer}

docs 中的更多信息。

HTTP API 还具有清除编排的方法。 single one by IDmultiple by datetime/status

DELETE <rooturl>/runtime/webhooks/durabletask/instances/{instanceId}
    ?taskHub={taskHub}
    &connection={connection}
    &code={systemKey}

最后,您还可以使用 C# 中的 DurableOrchestrationClient API 管理您的实例。这是 GitHub 上的示例:HttpGetStatusForMany.cs

我有 writtenvlogged 关于使用 DurableOrchestrationClient API 的信息,如果您想了解更多关于如何在 C# 中使用它的信息。

自定义状态

小补充:可以将custom status object 添加到编排中,这样您就可以添加有关编排进度的丰富信息。

获取持续时间

当您查询编排实例的状态时,您会返回一个 DurableOrchestrationStatus 对象。这包含两个属性:

  • 创建时间
  • 上次更新时间

我猜你可以减去这些并得到一个合理的指示它所花费的时间。

【讨论】:

    【解决方案2】:

    您可以使用Azure Functions Core Tools 管理 Durable Functions 编排实例。

    Terminate instances

    func durable terminate --id 0ab8c55a66644d68a3a8b220b12d209c --reason "It was time to be done."
    

    Query instances with filters:你可以添加参数(runtime-status)来过滤正在运行的实例。

    func durable get-instances --created-after 2018-03-10T13:57:31Z --created-before  2018-03-10T23:59Z --top 15
    

    至于函数耗时,貌似不支持。类似的参数是get-history

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-11
      • 2012-05-19
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      相关资源
      最近更新 更多