I have a function app with the following code
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, TraceWriter log)
This executes my function every 5 seconds. In production I want the interval to be 30 seconds. After I publish the function to Azure it works and is run every 5 seconds.
On the top of the Integrate -page in the Function settings there is a message "Your app is currently in read-only mode because you have published a generated function.json. Changes made to function.json will not be honored by the Functions runtime" and the page is greyed out.
So how do I have different schedule for my timer function in development and production?
In the Azure portal, browse to your function app. Under Settings, choose Configuration. In the Function runtime settings tab, locate the Runtime version. Note the specific runtime version.
Locate the host. json file underneath the WWWROOT folder / directory within the App. By default this file will be empty. You can then add the functionTimeout property and set it to your desired timeout threshold, such as 10 minutes (00:10:00).
How Long Can Azure Functions Run? For any Azure Functions, a single Function execution has a maximum of 5 minutes by default to execute. If the Function is running longer than the maximum timeout, then the Azure Functions runtime can end the process at any point after the maximum timeout has been reached.
When you create an Azure Function with a timer trigger, you have to set the timer schedule in code, in the RunAsync method. This doesn’t provide for very much flexibility as you will need to redeploy the whole function if you want to change the schedule. I’m here to to tell you you don’t have to!
Follow the below steps to Publish Azure Functions Time Trigger From Visual Studio 2019. Right click on the Azure Functions Time Trigger project and click on the Publish button Click on the Azure Functions Consumption Plan, select the Create New option, and then click on the Create Profile button. Provide the below details as high lighted
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. Now, click on the Timer trigger and then click on the Monitor tab as shown below. The Monitor tab shows all the invocations.
The time-triggered Azure Function allows us to schedule time for executing the function. It means that it triggers the function on a specified time. It works as CRON expressions work.
Make your schedule configurable. Declare it like this in code:
[TimerTrigger("%schedule%")]
Then add the development setting named schedule
with value */5 * * * * *
and production setting with value */30 * * * * *
.
This should sum up the other answers given here:
Configure local settings
{
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"schedule": "*/5 * * * * *",
"//": "put additional settings in here"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "XXXXXXXXXX"
}
}
[TimerTrigger("%schedule%")]
Configure Azure
Application settings
Add new setting
schedule
as key and */30 * * * * *
as value save
on the top left If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With