简体   繁体   English

Azure耐用功能如何恢复?

[英]How do Azure Durable Functions resume?

I'm looking at Azure Durable Functions extension (and the Durable Task framework repo ) and looking for the technical details of how it handles the following scenario. 我正在查看Azure耐用功能扩展 (和耐用任务框架repo ),并寻找如何处理以下情况的技术细节。

Imagine the following orchestration. 想象以下编排。

var result1 = await client.PostAsync("http://some-external-service.com/...", input);

var result2 = await context.CallActivityAsync<string>("Other Function","some data");

... do more stuff with result1 and result2

Imagine the function was resumed after Other Function finished, on a machine that was not the first. 想象一下,在“ Other Function完成之后,该功能是在不是第一台计算机上恢复的。 How does the framework resume from the second await, without executing the first? 框架如何从第二个等待中恢复,而不执行第一个?

In fact, is there a possibility that the HTTP call can be executed more than once in this case? 实际上,在这种情况下,是否可以多次执行HTTP调用?


I looked at the Microsoft Bot Framework which has a similar resuming strategy which serializes and rehydrates Dialog stack. 我看了一下Microsoft Bot Framework,它具有类似的恢复策略,可以对Dialog堆栈进行序列化和重新水化。 (This forced writing code that does not refer to outer scope, so the function itself can be serialized .etc.) (此强制编写的代码未引用外部作用域,因此该函数本身可以序列化等等。)

I'm interested in the core functionality in .NET Tasks (or Durable Tasks) which allows serializing and resuming a Task on a different machine without re-running the part it already executed (potentially on a different machine). 我对.NET Tasks(或Durable Tasks)中的核心功能感兴趣,该功能允许在另一台计算机上序列化和恢复Task ,而无需重新运行已执行的部分(可能在另一台计算机上)。

Actually it will execute HttpClient call for the second time when running the function after CallActivity is completed. 实际上,在CallActivity完成后,在运行该函数时, CallActivity第二次执行HttpClient调用。

That's why documentation says : 这就是为什么文档说

Orchestrator code must never initiate any async operation except by using the DurableOrchestrationContext API. 除非使用DurableOrchestrationContext API,否则Orchestrator代码不得启动任何异步操作。 For example, no Task.Run, Task.Delay or HttpClient.SendAsync. 例如,没有Task.Run,​​Task.Delay或HttpClient.SendAsync。

So, if you need to call external HTTP point, you should wrap this call inside an activity function and then call it from orchestrator. 因此,如果需要调用外部HTTP点,则应将此调用包装在活动函数中,然后从Orchestrator进行调用。 Activity call results are saved to Table Storage, so the next call to await will return result from there, short-circuiting the call to activity function. 活动调用结果将保存到表存储中,因此下一个对await调用将从那里返回结果,从而使对活动函数的调用短路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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