Human Interaction - Part 6 - Azure Durable Functions
Human Interaction - Part 6 - Azure Durable Functions
• Azure Functions, Serverless, .NET, Azure
• 4 min read
The Human Interaction pattern enables, as the name suggests, human interaction in orchestrators. Automated processes might require some human intervention, and this is the pattern for scenarios like that.
This is a series where I am explaining the components of durable functions1 and the different application patterns of implementation.
In this flow, the orchestration starts an activity that requires some human interaction, the orchestrator then waits for the interaction that comes from an external event, which is basically represented by an HTTP endpoint exposed by the orchestrator. To prevent that human interaction is missed or delayed, timeouts are applied in this pattern.
This example shows really well how to adopt the pattern. It is a classic example of an approval process that is started, and in case the human interaction takes too long or doesn’t occur, the orchestrator escalates the request.
The HumanInteraction_HttpStart is the HTTP Trigger.
Starter Function (aka DurableClient)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[FunctionName($"{nameof(HumanInteraction)}_HttpStart")]publicasyncTask<HttpResponseMessage>HttpStart([HttpTrigger(AuthorizationLevel.Anonymous,"post")]HttpRequestMessagereq,[DurableClient]IDurableOrchestrationClientstarter,ILoggerlog){varexpenseClaim=awaitreq.Content.ReadAsAsync<ExpenseClaim>();varinstanceId=awaitstarter.StartNewAsync<ExpenseClaim>(nameof(Constants.RunOrchestrator),expenseClaim);log.LogInformation($"Started orchestration with ID = '{instanceId}'.");returnstarter.CreateCheckStatusResponse(req,instanceId);}
Looking at the Orchestrator, it receives the ExpenseClaim, which is then raised for approval on the activity RunRequestApproval. The timeout is then created using a Timer with a due time.
From this moment, through the External Event endpoint, approval occurs. This endpoint is automatically exposed when the Orchestrator starts:
If approved it runs the activity RunProcessApproval, otherwise, it runs the activity RunEscalation.
For the external event, the CURL request is used to raise an event with the approval response. The URL below is output when the Orchestrator is started, as explained before:
Join the conversation! Share your thoughts and connect with other readers.