Dela via


TimerTrigger Interface

Implements

java.lang.annotation.Annotation

public interface TimerTrigger
implements java.lang.annotation.Annotation

The timer trigger lets you run a function on a schedule by specifying a CRON expression for when the function should run. For more details and examples on how to specify a CRON expression, refer to the schedule() attribute of this annotation.

An example of using the timer trigger is shown below, where the keepAlive function is set to trigger and execute every five minutes:

@FunctionName("keepAlive")
 public void keepAlive(
    @TimerTrigger(name = "keepAliveTrigger", schedule = "0 */5 * * * *") String timerInfo,
     ExecutionContext context
 ) {
     // timeInfo is a JSON string, you can deserialize it to an object using your favorite JSON library
     context.getLogger().info("Timer is triggered: " + timerInfo);
 }

Method Summary

Modifier and Type Method and Description
abstract java.lang.String dataType()

Defines how Functions runtime should treat the parameter value.

abstract java.lang.String name()

The name of the variable that represents the timer object in function code.

abstract java.lang.String schedule()

A CRON expression in the format {second} {minute} {hour} {day} {month} {day-of-week}.

Method Details

dataType

public abstract String dataType()

Defines how Functions runtime should treat the parameter value. Possible values are:

  • "": get the value as a string, and try to deserialize to actual parameter type like POJO
  • string: always get the value as a string
  • binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]

Returns:

The dataType which will be used by the Functions runtime.

name

public abstract String name()

The name of the variable that represents the timer object in function code.

Returns:

The name of the variable that represents the timer object in function code.

schedule

public abstract String schedule()

A CRON expression in the format {second} {minute} {hour} {day} {month} {day-of-week}.

| --------------------------------------------- | ------------------ |
| Goal                                          | CRON Expression    |
| To trigger once every five minutes:           | 0 \*/5 \* \* \* \* |
| To trigger once at the top of every hour:     | 0 0 \* \* \* \*    |
| To trigger once every two hours:              | 0 0 \*/2 \* \* \*  |
| To trigger once every hour from 9 AM to 5 PM: | 0 0 9-17 \* \* \*  |
| To trigger at 9:30 AM every day:              | 0 30 9 \* \* \*    |
| To trigger at 9:30 AM every weekday:          | 0 30 9 \* \* 1-5   |

Returns:

A string representing a CRON expression that will be used to schedule a function to run.

Applies to