Azure Functions – Timer Triggers – Configurable Scheduled Expressions

In this article, we will learn how to edit the Scheduled Expression (the frequency of execution of a timer trigger) using a Configurable item in the App Settings of Azure Functions.

Create an Azure Function App using Azure Portal as shown below. You can use language of your choice.

1.CreateFunctionApp

Once you review all the details, click on Review + Create button to create the Azure Function app. Below is how it looks after you create the Function App.

2.Function Listing

Now, create an Azure Function project using Visual Studio (prefer latest version) and choose the appropriate Azure Function runtime and then choose Timer Trigger. Once you create the Function app, it should look something as shown below where the Scheduled Expression is hard coded.

2-Visual Studio - Timer Trigger

It’s a Cron Expression that tell us that the function executes once every 5 minutes. As it is obvious that the expression is hard coded which is not a best practice.

In order to make it dynamic, let use Binding Expressions to make the Cron expression to be a configurable item.

Let’s open the appsettings.json and add a setting called timer-frequency along with the appropriate value as shown below.

3.Config in Visual Studio

Now, create an App Setting with the same key name that you have created for storing the CRON Expression as shown below.

4.CreateAppSetting

Now, publish the application to the Azure Function app that you have created. Once the application is published, you will be able to view the Timer trigger Function in the Azure Portal as shown below.

5.Functions

Now, click on the Timer trigger and then click on the Monitor tab as shown below. The Monitor tab shows all the invocations.

6.First Execution

As the CRON expression that we configured in the App Settings was execute every five minutes, I had to wait for 5 minutes to view the above output.

Let’s change it to one minute by navigating to the Configuration blade as shown below.

7.Change Frequency

Click on OK and then click on Save in the Configuration blade – This is important 😊

Now, go back to Monitor section and you should see the output every one minute as shown below.

8. Monitor Every minute

That’s it. Happy Serverless programming 🙂

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s