EMAS Serverless supports time triggers for functions. This topic describes how to use this feature.
Procedure
Log on to the EMAS console. Select Serverless and click Enter to open the Serverless console.
In the left navigation pane, select Functions.
Select a function and click its name, such as test, to open the function details page.
On the Trigger tab, click the Edit button to the right of Scheduled Task Trigger.
On the Edit Function page, enter a cron expression as shown in the following figure.
The TimingTriggerConfig parameter is a cron expression. For example, 0 0 * * * * triggers the function every hour on the hour.
Configuration rules
Time triggers can only be configured using cron expressions.
Limits on cron expressions:
Cron expressions cannot contain extra spaces.
The maximum trigger frequency for a function is once per minute. Therefore, the Seconds field in the cron expression must be a specific number. Special characters are not supported for this field.
The Year field is not supported in cron expressions.
NoteYou cannot specify values for both the Day-of-month and Day-of-week fields in the same cron expression. At least one of these fields must contain an asterisk (*) or a question mark (?).
Cron expression syntax:
A cron expression consists of six required fields that are separated by spaces. Each field has a specific range of valid values.
Position
Field
Allowed values
Special characters
1
Seconds
0-59
Not supported
2
Minutes
0-59
Comma (,), hyphen (-), asterisk (*), forward slash (/)
3
Hours
0-23
Comma (,), hyphen (-), asterisk (*), forward slash (/)
4
Day
1-31 (depends on the month)
Comma (,), hyphen (-), asterisk (*), forward slash (/)
5
Month
Enter a number from 1 to 12 or the three-letter abbreviation of the month in uppercase: {JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC}.
Comma (,), hyphen (-), asterisk (*), forward slash (/)
6
Week
Enter a number from 0 to 7 or the three-letter abbreviation of the day of the week in uppercase: {MON|TUE|WED|THU|FRI|SAT|SUN}. Both 0 and 7 represent Sunday.
Comma (,), hyphen (-), asterisk (*), forward slash (/)
Special character descriptions:
Special character
Meaning
Comma (,)
Lists enumerated values. For example, in the Hours field,
2,3,4specifies 2:00, 3:00, and 4:00.Hyphen (-)
Specifies a range. For example, in the Day-of-month field,
1-5includes the 1st through the 5th day of the month.Asterisk (*)
Represents all values in the field. For example, in the Hours field,
*means every hour.Question mark (?)
Specifies no specific value. You can use this character in the Day-of-month or Day-of-week field.
Forward slash (/)
The process is triggered at the start time and then recurs at a fixed interval.
For example, in the minute field, enter
1/10to specify that the job is triggered every 10 minutes starting from the first minute of the hour, such as at the 11th, 21st, and 31st minutes, and so on.
Function input parameters
In a function, you can retrieve the runtime parameters from ctx.args. The following example shows the parameters that are passed when a function is triggered by a time trigger:
{
"userPayload": "This is task paramters",
"triggerTime": "2023-03-01T07:27:30Z",
"triggerName": "TIMER_LATEST"
}
Where:
triggerName: The name of the trigger. For a time trigger, this value is always `TIMER_LATEST`.
triggerTime: The time when the function is triggered. The actual trigger time may be slightly later than the time specified in the cron expression.