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.

Advertisements

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
Advertisements

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.

Advertisements

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.

Advertisements

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 😊

Advertisements

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 🙂

Advertisements

Do you like this article? If you want to get more updates about these kind of articles, you can join my Learning Groups

WhatsApp

Telegram

Advertisements
Advertisements

5 comments

  1. Do you know of a solution where this schedule can apply to a single trigger in a function app that contains multiple timer triggers?

    Like

  2. Is there a way to set a specific triggers’ schedule when a function app contains multiple timer triggers using this method?

    Like

Leave a comment