I have a Function (HttpTrigger) that can take a bit to run 5-10 minutes. It reads some information from the body of the request to perform some actions:
[FunctionName("myFunc")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string responseMessage = string.Empty;
var content = await new StreamReader(req.Body).ReadToEndAsync();
myClass body = JsonConvert.DeserializeObject<myClass>(content);
for (int i = 0; i < 10; i++)
{
anotherFunctionAsync(i, myClass).GetAwaiter().GetResult();
// Perform tasks totaling 5-10 minutes
}
return new OkObjectResult("everything went ok");
}
However often I run into issues in my Data Factory where I will get an error like:
Operation on target your_function failed: Call to provided Azure function 'myFunc' failed with status-'BadGateway' and message 502 - Web server received an invalid response while acting as a gateway or proxy server.
I understand that this is due to the Function running for a long time.
How can I deal with this, such that Data Factory waits for the function to properly complete and not fail (when it is still running)?
I have already taken a look at the Durable Functions and Best Practices, but I don't know how to apply it when it has to communicate with Data Factory.
Since the function I call is async, could I just remove waiting for response?


