-
Notifications
You must be signed in to change notification settings - Fork 13
/
HttpStart.cs
57 lines (52 loc) · 2.44 KB
/
HttpStart.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Net.Http;
using System.Threading.Tasks;
using DurableFunctions.Demo.DotNetCore.Chaining.Orchestrators;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
// ReSharper disable once CheckNamespace
namespace DurableFunctions.Demo.DotNetCore.Starters
{
public class HttpStart
{
/// <summary>
/// This function starts a new Orchestrator in the same Function App
/// which matches the OrchestratorName parameter.
/// </summary>
/// <param name="req">The HttpRequestMessage which can contain input data for the Orchestrator.</param>
/// <param name="orchestratorClient">An instance of the DurableOrchestrationClient used to start a new Orchestrator.</param>
/// <param name="orchestratorName">The name of the Orchestrator function to start.</param>
/// <param name="id">Optional id for the Orchestrator function instance.</param>
/// <param name="log">ILogger implementation.</param>
/// <returns>An HttpResponseMessage containing the id and status of the Orchestrator instance.</returns>
[FunctionName(nameof(HttpStart))]
public async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "start/{orchestratorName}/{id?}")]HttpRequestMessage req,
[DurableClient]IDurableClient orchestratorClient,
string orchestratorName,
string id,
ILogger log)
{
var orchestratorInput = await req.Content.ReadAsAsync<object>();
string instanceId = id;
if (string.IsNullOrEmpty(instanceId))
{
// Start a new Orchestrator and let Durable Functions generate the instance id.
instanceId = await orchestratorClient.StartNewAsync(
orchestratorName,
orchestratorInput);
}
else
{
// Start a new Orchestrator and use your own instance id.
instanceId = await orchestratorClient.StartNewAsync(
orchestratorName,
instanceId,
orchestratorInput);
}
log.LogInformation($"Started Orchestrator with ID = '{instanceId}'...");
return orchestratorClient.CreateCheckStatusResponse(req, instanceId);
}
}
}