Skip to content

Instantly share code, notes, and snippets.

@laur3d
Created September 11, 2020 06:58
Show Gist options
  • Save laur3d/7f18337dea4dd4e57909f988fc76d52e to your computer and use it in GitHub Desktop.
Save laur3d/7f18337dea4dd4e57909f988fc76d52e to your computer and use it in GitHub Desktop.
DynamicOrchestrators
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