Skip to main content

Scheduled trigger

You can use Timer Trigger combined with Cloud Function to implement the scheduled task feature.

Setting Up Scheduled Trigger

Go to Cloud Development Platform/Cloud Functions, choose the function to configure, click Edit, modify the Scheduled Trigger option in the form, and you can upload a configuration file or configure the content. The format is as follows:

{
// The triggers field is an array of triggers. Currently, only one trigger is supported, meaning the array can contain only one element and multiple entries are not allowed.
"triggers": [
{
// name: trigger name, rules are described below
"name": "myTrigger",
// type: trigger type. Currently, only `timer` (namely scheduled trigger) is supported.
"type": "timer",
// config: trigger configuration. For scheduled triggers, the config format is a cron expression. Rules are described below.
"config": "0 0 2 1 * * *"
}
]
}

Detailed Configuration Explanation

Field Rules

  • Scheduled trigger name (name): Supports up to 60 characters, including a-z, A-Z, 0-9, -, and _. Must start with a letter. Multiple scheduled triggers with the same name are not supported under a single function.
  • Trigger cycle (config): The scheduled trigger time for the function. Enter a custom standard Cron expression to determine when to trigger the function. For more information about Cron expressions, refer to the following.

Cron Expression

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

OrderFieldValue
First PositionSecondsInteger from 0 - 59
Second PositionMinutesInteger from 0 - 59
Third PositionHoursInteger from 0 - 23
Fourth PositionDay of MonthInteger from 1 - 31 (must consider the number of days in the month)
Fifth PositionMonthInteger from 1 - 12 or JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
Sixth PositionDay of WeekInteger from 0 - 6 or MON, TUE, WED, THU, FRI, SAT, SUN, where 0 is Sunday, 1 is Monday, and so on
Seventh PositionYearInteger from 1970 - 2099

Wildcard

WildcardMeaning
,Represents the union of comma-separated values. For example, in the "hour" field, '1,2,3' represents hours 1, 2, and 3.
-Includes all values within 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 represents every hour.
/Specifies increments. In the "minute" field, entering '1/10' specifies repetition every ten minutes starting from the first minute. For example, the 11th minute, 21st minute, 31st minute, and so on.
Note

In a Cron expression, when both the "day" and "day of week" fields are specified, they have an OR relationship, meaning both conditions are effective.

cronjob example

The following lists some Cron expressions and their corresponding meanings:

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