Home > Net >  azure functions - how to schedule work with possible cancelation
azure functions - how to schedule work with possible cancelation

Time:04-06

I'm trying to build an app to help a friend with diabetes. The diabetic will click a check in button on a phone app which will call an azure function passing an email address/mobile number etc, a duration stating when they can next check in, and another duration which specifies when it is too late to check in. If the diabetic doesn't check in during the allowed window an email or text will be sent to alert someone that the diabetic hasn't checked in. If they click the button in the next check in window the previously scheduled work needs to be cancelled (or perhaps something with state needs to be set that can then be checked before sending the email).

I have built the phone app and have managed to get a HttpTriggered function to email me. I'm now a little bit stuck. How do I schedule something to happen at a specific point in the future and how could I cancel it following the correct user interaction? Any help would be much appreciated.

CodePudding user response:

How do I schedule something to happen at a specific point in the future

You can make use of a Queue triggered Function (you can either use Azure Storage Queue or Azure Service Bus Queue).

Basically the idea is that you send the message to the queue with a visibility timeout so that the message only appears in the queue when you are ready to process it. This you can do in your HTTP triggered Function.

how could I cancel it following the correct user interaction?

This is where things get interesting!

The way you could do it is have some field in your database which would indicate that the user has already interacted and no further processing would be required.

Your Queue triggered Function would still fire but what you would do is first check your database if any further action is required.

If no action is required, then you would simply let the Function complete so that the message is removed from the queue.

If any action is required, then you would perform that action and then let the Function complete so that the message is removed from the queue.

CodePudding user response:

I suggest you look into Durable Functions, which is an extension for Azure Functions (installed as a NuGet package) that allows running long running workflows (incl waiting for events and timers).

This extension uses storage queues and tables under the hood, but you only need to know the Durable Functions API. You also don't need to provision any other Azure services, since a Storage Account is already used by your Function App.

In your case you could use the Human Interaction pattern in combination with timers.

I have quite some video's explaining Durable Functions, you might find these helpful: https://youtube.com/playlist?list=PLoSzmz8jSD1fahiSdKdf4073AOdti_rx8.

  • Related