Skip to content

Instantly share code, notes, and snippets.

@gled4er
Created November 28, 2017 05:11
Show Gist options
  • Save gled4er/16970c68e0eb650cf363db6efe8a5741 to your computer and use it in GitHub Desktop.
Save gled4er/16970c68e0eb650cf363db6efe8a5741 to your computer and use it in GitHub Desktop.
Sync Response Orchestration Client
[FunctionName("SyncResponseClient")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "orchestrator/{functionName}")] HttpRequestMessage req,
[OrchestrationClient] DurableOrchestrationClient starter,
string functionName,
TraceWriter log)
{
// Function input comes from the request content.
dynamic eventData = await req.Content.ReadAsAsync<object>();
string instanceId = await starter.StartNewAsync(functionName, eventData);
log.Info($"Started orchestration with ID = '{instanceId}'.");
var responseMessage = starter.CreateCheckStatusResponse(req, instanceId);
var clientResponse = JsonConvert.DeserializeObject<OrchestrationClientResponse>(await responseMessage.Content.ReadAsStringAsync());
var executionDetails = Helper.GetExecutionDetails();
var durableFunctionSyncResponseService = new DurableFunctionSyncResponseService();
var result = await durableFunctionSyncResponseService.ProvideOutput(clientResponse, executionDetails, log);
return result == null
? req.CreateResponse(HttpStatusCode.OK, $"The operation is taking more than expected. Keep following the progress here {clientResponse.StatusQueryGetUri}") :
req.CreateResponse(HttpStatusCode.OK, result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment