Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I implement async "fire and forget" HTTP triggers in azure functions

I have an azure functions app that has a long running operation. I would like to trigger it via HTTP (for simplicity) with some input and no output. I don't want to keep the HTTP connection open for the whole time that the job is running.

What are my options for building a functions app where the runtime accepts some data and then immediately returns control to the caller before invoking my run.csx file?

like image 361
Joon Avatar asked Jun 30 '16 13:06

Joon


People also ask

How to create an HTTP triggered Azure function?

On the new function, select the HTTP trigger Azure function template. Now in the next window, Provide a name for the HTTP triggered Azure Function and then choose the Authorization level as function and then click on the Create Function to create the HTTP triggered Azure function.

How to add a timer Trigger in Azure Functions?

Now the next is, we will have to add a trigger, To add the trigger, we need to create an Azure Function. Click on the Functions link from the left navigation and then click on the + Add button on the Function app page as highlighted below. On the New Function window, select the template as Timer trigger as shown below.

What is an HTTP trigger?

The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is:

What is a trigger in Python?

Triggers are what cause a function to run. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function.


1 Answers

I'd recommend a design where your http function accepts + validates the work request and enqueues a message to a work queue that another function is listening on. So you'd start from the http trigger template, and add a queue output binding.

This way your request returns immediately, and your long running work can be done in the context of a Queue triggered function. One benefit is that you'll get the retry behavior of queue triggers for free. E.g. if your long running task fails half way through, the message will be reprocessed after some time (queue messages are only deleted from the queue after they are successfully processed).

The separation also gives you more options in the future for how the work is scheduled. E.g. the work could be kicked off via a queue output of another function in the future, w/o requiring an http request.

like image 112
mathewc Avatar answered Sep 21 '22 15:09

mathewc