Reputation: 2147
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?
Upvotes: 5
Views: 2856
Reputation: 13558
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.
Upvotes: 9