title | description | services | documentationcenter | author | manager | editor | tags | keywords | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Azure Functions timer trigger | Microsoft Docs |
Understand how to use timer triggers in Azure Functions. |
functions |
na |
christopheranderson |
erikre |
azure functions, functions, event processing, dynamic compute, serverless architecture |
d2f013d1-f458-42ae-baf8-1810138118ac |
functions |
multiple |
reference |
multiple |
na |
10/31/2016 |
chrande; glenga |
[!INCLUDE functions-selector-bindings]
This article explains how to configure and code timer triggers in Azure Functions. Azure Functions supports the trigger for timers. Timer triggers call functions based on a schedule, one time or recurring.
The timer trigger supports multi-instance scale-out. One single instance of a particular timer function is run across all instances.
[!INCLUDE intro]
The timer trigger to a function uses the following JSON object in the bindings
array of function.json:
{
"schedule": "<CRON expression - see below>",
"name": "<Name of trigger parameter in function signature>",
"type": "timerTrigger",
"direction": "in"
}
The value of schedule
is a CRON expression that includes 6 fields:
{second} {minute} {hour} {day} {month} {day of the week}
. Many of the cron expressions you find online omit the
{second}
field. If you copy from one of them, you need to adjust for the extra {second}
field. For specific examples, see
Schedule examples below.
The default time zone used with the CRON expressions is Coordinated Universal Time (UTC). If you want your CRON expression to be based on another time zone, create a new app setting for your function app named WEBSITE_TIME_ZONE
. Set the value to the the name of the desired time zone as shown in the Microsoft Time Zone Index.
For example, Eastern Standard Time is UTC-05:00. If you want your timer trigger to fire at 10:00 AM EST every day, your could use the following CRON expression which accounts for UTC time zone:
"schedule": "0 0 15 * * *",
Alternatively, you could add a new app setting for your function app named WEBSITE_TIME_ZONE
and set the value to Eastern Standard Time. Then the following CRON expression could be used for 10:00 AM EST:
"schedule": "0 0 10 * * *",
Here are some samples of CRON expressions you can use for the schedule
property.
To trigger once every 5 minutes:
"schedule": "0 */5 * * * *"
To trigger once at the top of every hour:
"schedule": "0 0 * * * *",
To trigger once every two hours:
"schedule": "0 0 */2 * * *",
To trigger once every hour from 9 AM to 5 PM:
"schedule": "0 0 9-17 * * *",
To trigger At 9:30 AM every day:
"schedule": "0 30 9 * * *",
To trigger At 9:30 AM every weekday:
"schedule": "0 30 9 * * 1-5",
When a timer trigger function is invoked, the timer object is passed into the function. The following JSON is an example representation of the timer object.
{
"Schedule":{
},
"ScheduleStatus": {
"Last":"2016-10-04T10:15:00.012699+00:00",
"Next":"2016-10-04T10:20:00+00:00"
},
"IsPastDue":false
}
Suppose you have the following timer trigger in the bindings
array of function.json:
{
"schedule": "0 */5 * * * *",
"name": "myTimer",
"type": "timerTrigger",
"direction": "in"
}
See the language-specific sample that reads the timer object to see whether it's running late.
public static void Run(TimerInfo myTimer, TraceWriter log)
{
if(myTimer.IsPastDue)
{
log.Info("Timer is running late!");
}
log.Info($"C# Timer trigger function executed at: {DateTime.Now}" );
}
let Run(myTimer: TimerInfo, log: TraceWriter ) =
if (myTimer.IsPastDue) then
log.Info("F# function is running late.")
let now = DateTime.Now.ToLongTimeString()
log.Info(sprintf "F# function executed at %s!" now)
module.exports = function (context, myTimer) {
var timeStamp = new Date().toISOString();
if(myTimer.isPastDue)
{
context.log('Node.js is running late!');
}
context.log('Node.js timer trigger function ran!', timeStamp);
context.done();
};
[!INCLUDE next steps]