Skip to main content

Timer Trigger

You can use Timer Trigger combined with cloud function to achieve the feature of scheduled tasks.

Configuring a Timer Trigger

Go to TCB/cloud function, select the function to be configured, click Edit, modify the Timer Trigger option in the form, and upload a configuration file or enter configuration content in the following format:

{
// The triggers field is a trigger array.
"triggers": [
{
// name: The name of the trigger. Refer to the description below for the rules.
"name": "myTrigger",
// type: Trigger type. Currently only supports timer (i.e., timer trigger)
"type": "timer",
// config: trigger configuration. Under the timer trigger, the format of config is a cron expression. Refer to the description below for the rules.
"config": "0 0 2 1 * * *"
}
]
}

Configuration Details

Field Rules

  • Timer trigger name (name): Supports up to 60 characters, including a-z, A-Z, 0-9, -, and _. Must start with a letter. Multiple timer triggers with the same name are not supported under a single function.
  • Timer trigger schedule (config): Specifies when the function is triggered. Enter a custom standard Cron expression to determine when to trigger the function. For more information about Cron expressions, see the following.

Cron Expression

Cron expressions have seven required fields, separated by spaces. Each field has its corresponding allowed values:

OrderFieldValue
First positionSecondInteger from 0-59
2ndminuteInteger from 0 - 59
3rdhourInteger from 0 - 23
4thDay of monthInteger from 1 - 31 (considering the number of days in the month)
5thMonthInteger from 1 - 12 or JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
6thDay of weekInteger from 0 - 6 or MON, TUE, WED, THU, FRI, SAT, SUN, where 0 represents Sunday, 1 represents Monday, and so on
7thYearInteger from 1970 - 2099

Wildcard

WildcardMeaning
,Represents the union of values separated by commas. For example: In the "hour" field, 1,2,3 represents 1:00, 2:00, and 3:00.
-Includes all values in the specified range. For example: in the "day" field, 1 - 15 includes the 1st to the 15th of the specified month.
*Represents all values. In the "hour" field, it indicates every hour.
/Specifies increments. In the "minute" field, entering 1/10 specifies repetition every 10 minutes starting from the first minute. For example, the 11th, 21st, 31st minutes, and so on.
Note

When both the "day" and "day of week" fields are specified in a Cron expression, they have an OR relationship, meaning both conditions will take effect.

cronjob Example

Here are some Cron expressions and their meanings:

  • */5 * * * * * * means triggers every 5 seconds
  • 0 0 2 1 * * * means triggers at 2:00 AM on the 1st day of every month
  • 0 15 10 * * MON-FRI * means triggers at 10:15 AM every day from Monday to Friday
  • 0 0 10,14,16 * * * * means triggers at 10:00 AM, 2:00 PM, and 4:00 PM every day
  • 0 */30 9-17 * * * * means triggers every half hour from 9:00 AM to 5:00 PM every day
  • 0 0 12 * * WED * means triggers at 12:00 PM every Wednesday