Scheduled Trigger
You can use the Scheduled Trigger combined with a cloud function to implement scheduled task functionality.
Configure Scheduled Trigger
- CloudBase Console
- CloudBase CLI Tool
Enter the Cloud Function Management Page, select the function to configure, click Edit, modify the Scheduled Trigger options in the form, and upload a configuration file or configuration content.
See the CloudBase CLI documentation.
Configuration Example
{
// The triggers field is an array of triggers. Currently, only one trigger is supported, meaning the array can only contain one element; multiple entries are not allowed.
"triggers": [
{
// name: trigger name, rules are described below
"name": "myTrigger",
// type: Trigger type. Currently only supports timer (which is a scheduled trigger)
"type": "timer",
// config: Trigger configuration. For timer triggers, the config should be a cron expression, and the rules are described below.
"config": "0 0 2 1 * * *"
}
]
}
Configuration Details
Field Rules
- Timer trigger name (name): supports up to 60 characters, supports
a-z
,A-Z
,0-9
,-
, and_
. It must start with a letter, and multiple timer triggers with the same name are not supported under a single function. - Timer trigger schedule (config): The scheduled function trigger time. Enter a custom standard Cron expression to determine when to trigger the function. For more information about Cron expressions, refer to the following content.
Cron Expression
A Cron expression has seven required fields, separated by spaces. Each field has a corresponding range of values:
Order | Field | Value |
---|---|---|
First | Seconds | 0 - 59 integer |
Second | Minutes | 0 - 59 integer |
Third | Hours | 0 - 23 integer |
Fourth | Day | 1 - 31 integer (considering the number of days in the month) |
Fifth | Month | 1 - 12 integer or JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, and DEC |
Sixth | Day of week | 0 - 6 integer or MON, TUE, WED, THU, FRI, SAT, and SUN, where 0 represents Sunday, 1 represents Monday, and so on |
Seventh | Year | 1970 - 2099 integer |
Wildcard
Wildcard | Meaning |
---|---|
, | 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 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 111th minute, the 21st minute, and the 31st minute, and so on. |
Note
When both the "day" and "day of week" fields are specified in a Cron expression, they are in an "OR" relationship, meaning both conditions take effect.
cronjob example
Below are some Cron expressions and their meanings:
*/5 * * * * * *
means trigger every 5 seconds0 0 2 1 * * *
means trigger at 2:00 AM on the 1st day of every month.0 15 10 * * MON-FRI *
means trigger at 10:15 AM every day from Monday to Friday.0 0 10,14,16 * * * *
means trigger at 10 AM, 2 PM, and 4 PM every day.0 */30 9-17 * * * *
means trigger every 30 minutes between 9:00 AM and 5:00 PM every day.0 0 12 * * WED *
means trigger at 12:00 PM (noon) every Wednesday.