Reputation: 3620
This is my Function.Json
{ "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.28", "configurationSource": "attributes", "bindings": [
{
"type": "timerTrigger",
"schedule": "*/5 * * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
} ], "disabled": false, "scriptFile": "../bin/PullRequest.dll", "entryPoint": "PullRequest.PullRequest.Run" }
This is my actual function:
[FunctionName("PullRequest")]
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, ILogger log)
{
if (myTimer.IsPastDue)
{
log.LogInformation("Timer is running late!");
}
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
When I tried to run this function on Azure portal then it only run once and stops.
this is the log of the Azure Funciton:
I rerun it and now it only running once.:
Upvotes: 2
Views: 3810
Reputation: 15571
Like DavidG said: the Logs you're showing us, show that the function PullRequest
ran at least 3 times.
executing
log line isn't visible, so the reason is not clearYour CRON expression */5 * * * * *
roughly translates into 'run this every time the number of seconds is divisible by 5'. That wouldn't match with the logs you're providing. Are you sure that's the CRON expression you're using?
Azure Functions uses the NCronTab library to interpret CRON expressions. A CRON expression includes six fields:
{second} {minute} {hour} {day} {month} {day-of-week}
Taken from Timer trigger for Azure Functions - CRON expressions.
EDIT:
Functions running on a Timer Trigger are automatically triggered on the specified timer intervals. To have the Functions actually run, you (of course) need to have something running that executes that trigger. Otherwise: how can they be triggered?
In Azure, the Functions Runtime is responsible for triggering the Function at the right time. Locally, the func.exe
tool that starts automatically when you debug the application will do this for you. But if that doesn't run, nothing will happen.
Azure Functions Core Tools lets you develop and test your functions on your local computer from the command prompt or terminal. Your local functions can connect to live Azure services, and you can debug your functions on your local computer using the full Functions runtime.
and
To run a Functions project, run the Functions host. The host enables triggers for all functions in the project.
Taken from Work with Azure Functions Core Tools.
In short: "The host enables triggers. It needs to run to have something that triggers any Function".
Upvotes: 1
Reputation: 764
Time trigger will automatically execute as per CORN expression i.e. in your case this function will execute every five seconds and If you run it from azure portal it will run only once.
If you want to check timings of last executions you can go to Monitor tab and check timings .
I have executed this locally and its working as expected
Upvotes: 1