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

A workflow is created. For more information, see Create flows.

Create a time-based schedule in the Serverless Workflow console

  1. Log on to the Serverless Workflow console.
  2. In the left-side navigation pane, click Flows.
  3. On the Flows page, click the name of the flow for which you want to create a time-based schedule.
    workflow-name
  4. On the Details page, click Schedule tab. In the Schedule Management section, click Create Schedule.
    create-trigger
  5. In the Create Schedule panel, configure the parameters and click OK.
    Parameter Configuration method Example
    Schedule Name Enter a name for the custom time-based schedule. schedule-test
    Expression Select a mode for configuring scheduling time and enter a value.

    Valid values:

    • Cron Expression: Use a standard cron expression to configure the scheduling time. For more information, see Parameters for time-based schedules.
    • Time Interval: Use the @every expression to configure the scheduling time.

      Specify the interval at which the flow is scheduled. Unit: minutes.

    Select Time Interval and set the time interval to 1, which indicates that the flow is scheduled every minute.
    Payload Enter a custom parameter in the JSON object format. {"key": "value"}
    Description Enter a description for the time-based schedule. test schedule
    Enable Schedule Enable or disable time-based schedule. Turn on the Enable Schedule switch.
    • After you create a time-based schedule, you can view it on the Schedule tab of the flow. create-result
    • In addition, you can view the scheduled execution records of the flow on the Executions tab of the flow. In this example, the flow is executed every minute. execution-result

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?.

  1. Optional:Run the following command to view the request parameters of the operation:
    aliyun fnf CreateSchedule help

    The following output is returned:

    Alibaba Cloud Command Line Interface Version 3.0.45
    
    Product: fnf (FunctionFlow)
    Link:    https://xxxxxxxx.html
    
    Parameters:
      --CronExpression String  Required
      --FlowName       String  Required
      --ScheduleName   String  Required
      --Description    String  Optional
      --Enable         Boolean Optional
      --Payload        String  Optional
      --RequestId      String  Optional
  2. Run the following command to create a time-based schedule:
    aliyun fnf CreateSchedule --FlowName test --ScheduleName "schedule-test" --CronExpression "@every 1m" --Payload "{\"key\":\"value\"}" --Description "test schedule" --Enable true

    The following output is returned:

    {
        "CreatedTime": "2020-05-22T09:22:03Z",
        "CronExpression": "@every 1m",
        "Description": "test schedule",
        "Enable": true,
        "LastModifiedTime": "2020-05-22T09:22:03Z",
        "Payload": "{\"key\":\"value\"}",
        "RequestId": "63ba5895-ef49-b262-cde6-************",
        "ScheduleId": "978be20f-cceb-4677-935c-************",
        "ScheduleName": "schedule-test"
    }

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 * *.

        Note

        If 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.

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.