Azure Functions are incredible at being able to complete computations on our behalf. The Monitor Pattern specifically allows an Azure Function to consistently check for the status of a long running process that has a completion time that is irregular or unfixed. With the Monitor pattern, we set a large time window for the task to complete within, then we also instruct the Function to keep checking on the status of the task over a known interval period (or even a flexible interval period should we choose depending on code logic). We also don't have to write separate polling code.
The following shows a short and very simplified example of an HTTP triggered Durable Function using a Monitor Pattern, that will be checking on a web page over a set period of 2months to see whether the Artemis-I Space mission has launched yet, checking on a daily interval, and then alert a recipient by email if it has launched:
The Orchestrator code:
The Activity Function fetches a web page and checks for satisfaction of conditions:
In Azure, the Function app is created on a Consumption plan as we only ever need to call the Http Function once. The Monitor Pattern we set up will manage the lifecycle of the process for us.
Logic App Setup for alerts
For alerting we can use any kind of alert we choose when our conditions are met. Here, I chose a Logic App on a Consumption Plan that will send an alert to a known email address:
The email option chosen here was Gmail Send Email V2. You will need grant the Azure Logic App permissions to a Signed-in Gmail account as it will use this Gmail account as the 'From' address:
Conclusions
Here are some reasons why we may want to use the Monitor Pattern in this particular case:
The launch of the Artemis mission is not entirely fixed. We know it's scheduled 'some time' in mid-November at the time of this writing but we don't know the exact time. Therefore we want to set our Azure Function interval check to every single day (24hrs or 1day) over a period that covers all of November because space launches can get delayed or done earlier in response to numerous variables.
We will only call the Function App once, the rest is self managed by our Montior pattern, meaning that based on our interval, and other code logic, the launch is more or less guaranteed to be captured and we will be alerted about it when code logic is satisfied.
Unlike a Timer-triggered Function that will forever execute based on the CRON schedule, this HTTP Triggered Durable Function will manage it's own lifecycle and not execute further until triggered again, all without needing to write extra polling code or callback Urls.
Ultimately, we probably want to use more nuanced and substantial ways of checking the contents of the web page compared to using phrase checks.