Scheduling work is a must in app development, I’m unsure how many Windows Task Scheduler I created during my years as a software developer but I’m sure one too many is the right answer.
Often as a Dev or DevOps we must solve simple requirements based on a schedule like running maintenance script, indexing content, checking state, triggering events, etc. Task Scheduler did the job but it lacked the finesse of an efficient execution monitoring and simple multi-environment deployment. We would almost always end up missing some tasks in lower environments or having to connect to servers to figure out why a task had stopped running or simply to see what was going on. In the end, Windows Task take less time to code then they take to maintain and that’s simply a bad omen.
In this article, I will walk you through the steps of creating an Azure function based on a time trigger with NuGet dependencies and custom app settings.
1. Creating an Azure function app
- First let’s create an Azure function app for your new trigger function.
- Go in Azure portal and create a Function App.
- Notice the choice between Consumption and App Service Hosting Plan.
- For now, select either one.
2. Create an Azure Trigger Function
- Click “+” on functions and choose a Timer template with your preferred language.
3- Azure Function development can be achieved directly in the browser web page
- Code & Compile directly in your browser;
- Enjoy in browser live execution logs.
4- Set your desired execution schedule
- Schedules can be set from the Integrate menu;
- The execution schedule uses a CRON expression in UTC time zone;
- This grants the flexibility and simplicity of configuring a schedule that will meet most business requirements;
- Configuration settings are persisted in the function.json file.
5- Leverage any NuGet packages
- You can add any code dependency using NuGet packages by creating a file name project.json and adding your dependencies there.
- This will make the package contents download and become directly available in your browser development IDE window.
6- Configure your function using appSettings
- In the Function Apps node, you can access the Platform features tab and set application settings to use within any of your functions.
7- Logging in Application Insight
- Even if Azure Function provides great logging and monitoring capabilities they are only for the Azure Function itself.
- Chances are that your Azure Function is only a small part of a larger application.
- In that case you might also want to log within your project Application insight instance.