Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change timer interval in Azure for Azure Function published from Visual Studio

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?

like image 928
Mathias Rönnlund Avatar asked Oct 27 '17 11:10

Mathias Rönnlund


People also ask

How do I change my Azure function runtime in Visual Studio?

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.

How do I increase the timeout on my Azure function?

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 an Azure function can run?

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.

Do I have to set the timer schedule for an azure function?

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!

How to publish Azure Functions time trigger from Visual Studio 2019?

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

How to monitor timer Trigger invocations in azure function?

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.

What is the time-triggered Azure function?

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.


Video Answer


2 Answers

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 * * * * *.

like image 190
Mikhail Shilkov Avatar answered Sep 30 '22 04:09

Mikhail Shilkov


This should sum up the other answers given here:

Configure local settings

  • add a local.settings.json file to your project.
  • insert the following code:
{
  "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"
  }
}
  • set the trigger attribute like
[TimerTrigger("%schedule%")]

Configure Azure

  • go to the Azure Portal and go to functions, click on your function and select Application settings
  • in the application setting select Add new setting
  • enter schedule as key and */30 * * * * * as value
  • click save on the top left
  • redeploy your function
like image 43
MovGP0 Avatar answered Sep 30 '22 04:09

MovGP0