简体   繁体   中英

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.

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


I looked at the Microsoft Bot Framework which has a similar resuming strategy which serializes and rehydrates Dialog stack. (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).

Actually it will execute HttpClient call for the second time when running the function after CallActivity is completed.

That's why documentation says :

Orchestrator code must never initiate any async operation except by using the DurableOrchestrationContext API. For example, no Task.Run, Task.Delay or 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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