All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.functions.annotation.TimerTrigger Maven / Gradle / Ivy

Go to download

This package contains all Java interfaces and annotations to interact with Microsoft Azure functions runtime.

The newest version!
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

package com.microsoft.azure.functions.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 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 {@link #schedule()} attribute of
 * this annotation.
 *
 * 

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

* *
{@literal @}FunctionName("keepAlive")
 * public void keepAlive(
 *    {@literal @}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);
 * }
* * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface TimerTrigger { /** * The name of the variable that represents the timer object in function code. * * @return The name of the variable that represents the timer object in function code. */ String name(); /** *

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[]
  • *
* @return The dataType which will be used by the Functions runtime. */ String dataType() default ""; /** * A CRON expression in the format * {@code {second} {minute} {hour} {day} {month} {day-of-week}}. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
A table showing some examples of CRON expressions that could be used.
GoalCRON 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
* * @return A string representing a CRON expression that will be used to schedule a function to run. */ String schedule(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy