Timer Trigger
This section describes how to create a timer trigger on the FunctionGraph console to trigger a function at a specified frequency.
Common application scenarios:
- Back up important data. For example, back up data every seven days.
- Monitors the server status and resource usage. For example, functions are executed and server usage reports are sent at 10:00 a.m. every day.
Overview
A timer trigger invokes a function based on a fixed frequency (minutes, hours, or days) or a specified Cron expression. It is suitable for scenarios where tasks need to be executed periodically.
You can use timer triggers for shared functions in the LA-Sao Paulo1 region.
Video Tutorial
This video shows how to use a timer trigger to invoke your function and check whether the function can be executed at the specified frequency.
Notes and Constraints
HTTP functions do not support timer triggers.
Prerequisites
You have created a function. For details, see Creating a Function from Scratch
Creating a Timer Trigger
- Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- Click the name of the function to be configured. The function details page is displayed.
You can configure a timer trigger for a shared function on the Shared page in the LA-Sao Paulo1 region. For details about shared functions, see Sharing Functions Based on RAM.
- Choose Configuration > Triggers and click Create Trigger, as shown in Figure 1.
- Configure the following parameters:
Table 2 Timer trigger parameters Parameter
Description
Example Value
Trigger Type
Select Timer.
Timer
Timer Name
Customize a name. The value can contain letters, digits, underscores (_), and hyphens (-). It must start with a letter and cannot exceed 64 characters.
Timer-fg
Rule
Trigger rule. You can select Fixed rate or Cron expression.
- Fixed rate: The function is triggered at a fixed rate of minutes, hours, or days. You can set a fixed rate from 1 to 60 minutes, 1 to 24 hours, or 1 to 30 days.
- Cron expression: The function is triggered based on a complex rule. For example, you can set a function to be executed at 08:30:00 from Monday to Friday. For more information, see Cron Expression Rules.
Fixed rate
1 minute
Enable Trigger
Determine whether to enable the timer trigger. If this parameter is disabled, the function will not be triggered at the specified frequency.
Enabled
Additional Information
Optional.
The additional information you configure will be put into the user_event field of the timer event source. For details, see Supported Event Sources.
-
- Click OK.
Viewing the Execution Result
After a timer trigger is created, the function will be executed periodically according to the configured trigger rule. You can view function run logs on the function details page.
- Return to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- On the Functions page, click the name of the function to be configured.
- Choose Monitoring > Logs to query function running logs.
Cron Expression Rules
You can configure a cron expression in the following two formats for a function timer trigger:
- @every format
@every Nunit. N is a positive integer. unit can be ns, µs, ms, s, m, or h. An @every expression means to invoke a function every N time units, as shown in Table 3.
- Standard format
The format is "seconds minutes hours day-of-month month day-of-week". day-of-week is optional. The fields must be separated from each other using a space. Table 4 describes the fields in a standard cron expression. For details about the special characters, see Table 7.
Table 4 Cron expression fields Field
Description
Value Range
Special Characters Allowed
CRON_TZ
Optional. If this parameter is not set, the region's time zone is used by default.
If your task will run in a specific time zone, use CRON_TZ to specify the time zone. For example, to trigger your function at 04:00 on the first day of each month (Beijing time), use CRON_TZ=Asia/Shanghai 0 0 4 1 * *.
The time zone expression varies depending on the region. Query the CRON_TZ expression of the required region. For details, see Table 8.
-
-
Seconds
Mandatory
0-59
, - * /
Minute
Mandatory
0-59
, - * /
Hours
Mandatory
0-23
, - * /
Day-of-month
Mandatory
1-31
, - * ? /
Month
Mandatory
1–12 or Jan–Dec. The value is case-insensitive, as shown in Table 5.
, - * /
Day-of-week
Optional
0–6 or Sun–Sat. The value is case-insensitive, as shown in Table 6. 0 means Sunday.
, - * ? /
Table 5 Value description of the month field Month
Digit
Abbreviation
January
1
Jan
February
2
Feb
March
3
Mar
April
4
Apr
May
5
May
June
6
Jun
July
7
Jul
August
8
Aug
September
9
Sep
October
10
Oct
November
11
Nov
December
12
Dec
Table 6 Value description of the day-of-week field Day of Week
Digit
Abbreviation
Monday
1
Mon
Tuesday
2
Tue
Wednesday
3
Wed
Thursday
4
Thu
Friday
5
Fri
Saturday
6
Sat
Sunday
0
Sun
Table 7 describes the special characters that can be used in a cron expression.
Table 7 Special character description Special Character
Meaning
Description
*
Used to specify all values within a field.
* in the minutes field means every minute.
,
Used to specify multiple values, which can be discontinuous.
For example, "Jan,Apr,Jul,Oct" or "1,4,7,10" in the month field and "Sat,Sun" or "6,0" in the day-of-week field.
-
Used to specify a range.
For example, "0-3" in the minutes field.
?
Used to specify something in one of the two fields in which the character is allowed, but not the other.
You can specify something only in the day-of-month or day-of-week field. For example, if you want your function to be executed on a particular day (such as the 10th) of the month, but do not care what day of the week that is, then put "10" in the day-of-month field and "?" in the day-of-week field.
/
Used to specify increments. The character before the slash indicates when to start, and the one after the slash represents the increment.
For example, "1/3" in the minutes field means to trigger the function every 3 minutes starting from 00:01:00 of the hour.
Table 8 describes several example cron expressions.
Table 8 Example cron expressions Function Scheduling Example
Cron Expression (Beijing Time)
12:00 every day
CRON_TZ=Asia/Shanghai 0 0 12 * * *
12:30 every day
CRON_TZ=Asia/Shanghai 0 30 12 * * *
26th, 29th, and 33rd minutes of each hour
CRON_TZ=Asia/Shanghai 0 26,29,33 * * * *
12:30 from Monday to Friday
CRON_TZ=Asia/Shanghai 0 30 12 ? * MON-FRI
Every 5 minutes during 12:00 and 14:59 from Monday to Friday
CRON_TZ=Asia/Shanghai 0 0/5 12-14 ? * MON-FRI
12:00 every day from January to April
CRON_TZ=Asia/Shanghai 0 0 12 ? JAN,FEB,MAR,APR *
Creating a Timer Trigger for a Shared Function
You can configure a timer trigger for a shared function in the LA-Sao Paulo1 region. For details about the shared function, see Sharing Functions Based on RAM.
- Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- On the Shared tab, click the function name to go to the function details page.
- The subsequent steps are the same as those for creating a common function. For details, see 3.
Helpful Links
- Manage function triggers through APIs. For details, see Function Trigger APIs.
- For the best practices of using a timer trigger in FunctionGraph, see Using FunctionGraph to Periodically Start and Stop ECSs.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot