Serverless Workflow allows you to schedule flow executions by configuring cron expressions. This topic describes how to create a time-based schedule for Serverless Workflow.
Prerequisites
Create a time-based schedule in the Serverless Workflow console
Create a time-based schedule by using Alibaba Cloud CLI
You must install and configure Alibaba Cloud CLI Before you use it. For more information, see What is Alibaba Cloud CLI?.
Parameters for time-based schedules
The parameters of a time-based schedule are in the following format:
{
payload: "payload"
cronExpression: "cronExpression"
enable: true|false
}
- payload: specifies the custom input of a time-based schedule in the JSON object format.
- cronExpression: specifies the time when the flow is scheduled. The scheduling time can be expressed
in one of the following forms:
Note The minimum scheduling interval is 1 minute. If the specified interval is shorter than 1 minute, it is invalid.
- @every Value Unit
The flow is scheduled at an interval specified by Value Unit. In the expression, Value is a positive integer and Unit is m.
Example Expression Scheduled every 5 minutes @every 5m Scheduled every 1.5 hours @every 90m - Time expressions
- Cron expressions
The cron expression uses Coordinated Universal Time (UTC). The standard cron expression is in the following format: Seconds Minutes Hours Day-of-month Month Day-of-week.
- Time zone expressions
If you want to schedule the flow based on a specific time zone, you can use the CRON-TZ expression. For example, if you want to trigger the flow at four o'clock in the morning of the first day of every month (UTC+8), you can set CRON-TZ to Asia/Shanghai 0 0 4 1 * *.
NoteIf your time zone uses summer time and winter time, the flow may be scheduled more or fewer times than expected during the changes between summer time and winter time. We recommend that you set the scheduling time outside of the change periods.
The following table describes common examples of time expressions. For example, if you want the workflow to be scheduled at 12:00 (UTC+8), the cron expression is 0 0 4 * * * and the time zone expression is CRON_TZ=Asia/Shanghai 0 0 12 * * *.
Example Cron expression Time zone expression Schedule the function at 12:00 every day 0 0 4 * * * CRON_TZ=Asia/Shanghai 0 0 12 * * * Schedule the function at 12:30 every day 0 30 4 * * * CRON_TZ=Asia/Shanghai 0 30 12 * * * Schedule the function at the 26th, 29th, and 33rd minutes in each hour 0 26,29,33 * * * * CRON_TZ=Asia/Shanghai 0 26,29,33 * * * * Schedule the function at 12:30 from every Monday to Friday 0 30 4 ? * MON-FRI CRON_TZ=Asia/Shanghai 0 30 12 ? * MON-FRI Schedule the function every 5 minutes from 12:00 to 14:00 every day from Monday to Friday 0 0/5 4-6 ? * MON-FRI CRON_TZ=Asia/Shanghai 0 0/5 12-14 ? * MON-FRI Schedule the function at 12:00 every day from January to April 0 0 4 ? JAN,FEB,MAR,APR * CRON_TZ=Asia/Shanghai 0 0 12 ? JAN,FEB,MAR,APR * - Field description
Field Value range Supported special characters Seconds 0 to 59 N/A Minutes 0 to 59 , - * / Hours 0 to 23 , - * / Day-of-month 1 to 31 , - * ? / Month 1 to 12 or JAN to DEC , - * / Day-of-week 1 to 7 or MON to SUN , - * ? - Special characters
Character Description Example * Indicates any or each. In the Minutes field, 0 indicates that the flow is executed at the 0th second of every minute. , Indicates the value list. In the Day-of-week field, MON indicate Monday, WED indicates Wednesday, and FRI indicates Friday. - Indicates a range. In the Hours field, 10-12 indicates the UTC time from 10:00 to 12:00. ? Indicates an uncertain value. This value is used with other specified values. For example, if you specify a specific date but you do not care what day of the week it is, you can use this special character in the Day-of-week field. / Indicates the increment of a value. For example, n/m means to add an increment m to n each time. In the minute field, 3/5 indicates that the flow is executed every 5 minutes starting from the 3rd minute.
- Cron expressions
- @every Value Unit
Input format
The time-based schedule will be performed to schedule your flow based on the following input format:
{
"triggerTime": "2020-01-01T00:00:00Z",
"triggerName": "time-trigger",
"payload": {
"key": "value",
"key_int": 1
}
}
- triggerTime: specifies the time when a flow is scheduled. A flow may be scheduled multiple times at a specified time. You can deduplicate scheduling based on the time.
- triggerName: specifies the name of the time-based schedule.
- payload: You can customize the input in the scheduling configuration. The flow expands the
input JSON string to the JSON dict format. You can read it in the flow definition
by using
$.payload.key
. For more information, see Inputs and outputs.