Triggers
Use trigger commands to create and delete scheduled triggers for cloud functions.
Trigger Configuration
Define triggers in the cloudbaserc.json configuration file:
{
"version": "2.0",
"envId": "xxx",
"functions": [
{
"name": "app",
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "0 0 2 1 * * *"
}
]
}
]
}
Trigger Configuration Items:
| Configuration | Required | Type | Description |
|---|---|---|---|
name | Yes | String | Trigger name, maximum 60 characters, supports a-z, A-Z, 0-9, - and _, must start with a letter |
type | Yes | String | Trigger type, currently only supports timer (scheduled trigger) |
config | Yes | String | Trigger configuration, uses standard Cron expression |
Create Trigger
# Create trigger for specified function
tcb fn trigger create <functionName>
# Create triggers for all functions in config file
tcb fn trigger create
Usage Examples:
# Create trigger for app function
tcb fn trigger create app
# Create triggers for all functions
tcb fn trigger create
Delete Trigger
# Delete specified trigger for specified function
tcb fn trigger delete <functionName> <triggerName>
# Delete all triggers for specified function
tcb fn trigger delete <functionName>
# Delete all triggers for all functions in config file
tcb fn trigger delete
Usage Examples:
# Delete myTrigger trigger for app function
tcb fn trigger delete app myTrigger
# Delete all triggers for app function
tcb fn trigger delete app
# Delete all triggers for all functions
tcb fn trigger delete
Cron Expression
Cron expressions have seven required fields, separated by spaces:
| Field Position | Field Name | Value Range | Wildcards |
|---|---|---|---|
| First | Second | 0-59 integers | , - * / |
| Second | Minute | 0-59 integers | , - * / |
| Third | Hour | 0-23 integers | , - * / |
| Fourth | Day | 1-31 integers | , - * / |
| Fifth | Month | 1-12 integers or JAN-DEC | , - * / |
| Sixth | Day of Week | 0-6 integers or MON-SUN (0 = Sunday) | , - * / |
| Seventh | Year | 1970-2099 integers | , - * / |
Wildcard Descriptions:
| Wildcard | Meaning | Example |
|---|---|---|
, | Union | In "Hour" field, 1,2,3 means 1 AM, 2 AM, and 3 AM |
- | Range including all values | In "Day" field, 1-15 means 1st to 15th |
* | All values | In "Hour" field, * means every hour |
/ | Increment | In "Minute" field, 1/10 means starting from 1st minute, every 10 minutes |
Common Examples:
*/5 * * * * * * Trigger every 5 seconds
0 0 2 1 * * * Trigger at 2 AM on the 1st of every month
0 15 10 * * MON-FRI * Trigger at 10:15 AM Monday to Friday
0 0 10,14,16 * * * * Trigger at 10 AM, 2 PM, 4 PM every day
0 */30 9-17 * * * * Trigger every half hour from 9 AM to 5 PM every day
0 0 12 * * WED * Trigger at noon every Wednesday
Important Notes
- Currently, one function only supports configuring one trigger
- CLI reads trigger configuration from
cloudbaserc.jsonand creates it - If config file has no trigger configuration, creation operation will fail
- In Cron expressions, when "Day" and "Day of Week" fields both specify values, they are in an "OR" relationship