# Creation of a Azure Timer Trigger Function to check every 15 minutes for a available vaccination slot

Creation of a Azure Timer Trigger Function to check every 15 minutes for an available vaccination slot : 
[Github Project Link](https://github.com/ElstonMisquitta88/Cowin/blob/main/README.md) 

**Azure Functions** is a serverless solution means you don't have to worry about the infrastructure and work on writing code.
 [Azure Functions Overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview) 


I will be using the following services : 

- 
Azure Function

- 
SendGrid - For sending email notifications

- 
Application Insights







**(1)** The First Step is create a Azure TimerTrigger  Function using VS Code.


```
        [FunctionName("FetchCowinData")]
        public static void Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, ILogger log)
        {
            // Code Here
        }
``` 
This will be triggered every 15 mins.

The following packages need to be added.
```
dotnet add package System.Collections --version 4.3.0
dotnet add package System.Net.Http --version 4.3.4  
dotnet add package  SendGrid
``` 


We will call the API  -  [Apisetu](https://apisetu.gov.in/api/cowin) for checking the available vaccination slots.
Data will be fetch per district code wise. If data is found an email will be triggered.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639245937711/QbN1-6xkG.png)


**(2)** Next Step is to create an Azure Fucntion app in the portal and publish the code via Visual Studio.

The Function app is created using a consumption model to minimize the cost.
You're only charged for the time that your function app runs. This plan includes a free grant on a per subscription basis. - [Estimating Consumption plan costs](https://docs.microsoft.com/en-us/azure/azure-functions/functions-consumption-costs?tabs=portal) 

The Config values used in the function was be set via 
Azure portal >> Function App >> Configuration


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639243377743/fuz6MVtwo.png)

The Values in local.settings.json will be overridden by the values in  
Function App >> Configuration

To make this even more secure we can set these values via an **Azure Key Vault**.


**(3)** SendGrid - Email service - You can register for a free account with a daily limit of 100 emails which is quite good for testing and development purposes.

Will be using SendGrid  to send email notifications.The number of emails triggered can be monitored via the SendGrid  dashboard.

**(4)** Application Insights-Useful to monitor your applications.
Here we will be using it to monitor the Azure function.
Live metrics is also available for providing real time data.


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639244664874/c_rjNKrKw.png)


Once the Function is running we get email notification if data is found via the API.
**Sample Email :
**
![cowin.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639243841944/wZ_54v6fd.png)




