Created
September 11, 2020 06:58
-
-
Save laur3d/7f18337dea4dd4e57909f988fc76d52e to your computer and use it in GitHub Desktop.
DynamicOrchestrators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DynamicOrchestratorTrigger | |
{ | |
[FunctionName("DynamicOrchestratorTrigger")] | |
public static async Task<IActionResult> RunAsync( | |
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] | |
HttpRequest req, ILogger log, | |
ExecutionContext executionContext, | |
[DurableClient] IDurableOrchestrationClient starter) | |
{ | |
log.LogInformation("C# HTTP trigger function processed a request."); | |
string name = req.Query["name"]; | |
var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | |
dynamic data = JsonConvert.DeserializeObject(requestBody); | |
name ??= data?.name; | |
if (name == null) | |
{ | |
return new BadRequestObjectResult("Please pass a name on the query string or in the request body"); | |
} | |
var orchestratorInput = new OrchestratorInput | |
{ | |
CorrelationId = new Guid(), | |
Name = name.ToString() | |
}; | |
var instanceId = await starter.StartNewAsync(nameof(DynamicOrchestrator), orchestratorInput); | |
DurableOrchestrationStatus durableOrchestrationStatus = await starter.GetStatusAsync(instanceId); | |
while (durableOrchestrationStatus.RuntimeStatus != OrchestrationRuntimeStatus.Completed) | |
{ | |
await Task.Delay(200); | |
durableOrchestrationStatus = await starter.GetStatusAsync(instanceId); | |
} | |
return (ActionResult) new OkObjectResult(durableOrchestrationStatus.Output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment