Create a time-based schedule

更新时间:
复制 MD 格式

Serverless Workflow allows you to schedule workflow executions by configuring cron expressions. This topic shows you how to create a time-based schedule for Serverless Workflow.

Prerequisites

A flow must exist.

Create a schedule in the console

  1. Log on to the Serverless Workflow console.

  2. Go to the Flow page. In the list of flows, click the Flow Name of the target flow.

  3. On the Flows page, click the Time-based Schedules tab, and in the Time-based Schedule Management area, click Create Time-based Schedule.

  4. In the Create Time-based Schedule panel, fill in the parameters, and then click OK.

    Parameter

    Actions

    Example

    Time-based schedule name

    Enter a custom name for the time-based schedule.

    schedule-test

    Trigger time configuration

    Select a scheduling method and enter a time rule.

    The following two expression types are supported:

    • Cron expression: Use a standard cron expression. For more information, see Schedule time parameters.

    • Time interval: Use an @every expression.

      The interval, in minutes, at which to run the workflow.

    Select Time interval and enter 1 to run the workflow every minute.

    Payload

    Custom parameters in JSON format.

    {"key": "value"}

    Description

    Enter a description for the time-based schedule.

    test schedule

    Enable time-based schedule

    Enable or disable the time-based schedule.

    Turn on the Enable time-based schedule switch.

    • After creating the schedule, you can view it on the workflow's Time-based Schedule tab.

    • On the workflow's Executions tab, you can view the execution history. Records from scheduled triggers shown on the Executions tab have names that start with scheduled-exec, a status of Succeeded, and an execution time in milliseconds. In this example, a new execution appears every minute.

Create a schedule using the CLI

To create a time-based schedule using Alibaba Cloud CLI, you must first install and configure it. For more information, see What is Alibaba Cloud CLI?.

  1. (Optional) Run the following command to view the request parameters for the CreateSchedule operation.

    aliyun fnf CreateSchedule help

    Expected output:

    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

    Expected output:

    {
            "CreatedTime": "2024-06-26T03:36:57Z",
            "CronExpression": "@every 1m",
            "Description": "test schedule",
            "Enable": true,
            "LastModifiedTime": "2024-06-26T03:36:57Z",
            "Payload": "{\"key\":\"value\"}",
            "RequestId": "c7034d83-d1ba-648c-f05c-156439a857d7",
            "ScheduleId": "b888a48f-229d-4b35-adc6-5c63a37cf3b1",
            "ScheduleName": "schedule-test"
    }

Schedule time parameters

A time-based schedule uses the following parameters:

{
    payload: "payload"
    cronExpression: "cronExpression"
    enable: true|false
}
  • payload: The custom input for the scheduled execution. The payload must be in JSON format.

  • cronExpression: The schedule for the workflow. The following two expression types are supported.

    Note

    Intervals shorter than 1 minute are invalid.

    • @every Value Unit

      This expression runs the workflow at a fixed interval. Value must be a positive integer and Unit must be "m" (minutes).

      Scenario example

      Expression

      Run every 5 minutes

      @every 5m

      Run every 1.5 hours

      @every 90m

    • Time expression

      • Cron expression

        By default, cron expressions use Coordinated Universal Time (UTC). The standard cron expression format is: Seconds Minutes Hours Day-of-month Month Day-of-week.

      • Time zone expression

        To run a task in a specific time zone, prefix the expression with CRON_TZ=<TIMEZONE>. For example, to trigger a flow at 04:00 on the first day of every month in the Asia/Shanghai time zone, you can use CRON_TZ=Asia/Shanghai 0 0 4 1 * *.

        Note

        If your time zone observes Daylight Saving Time (DST), you may see duplicate or missed executions during DST transitions. We recommend that you avoid scheduling runs during these transition windows.

      The following table provides common examples of time expressions. For example, if you want a workflow to be scheduled at 12:00 Beijing Time, the corresponding 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 a workflow to run at 12:00 every day.

      0 0 4 * * *

      CRON_TZ=Asia/Shanghai 0 0 12 * * *

      Schedule a workflow to run at 12:30 every day.

      0 30 4 * * *

      CRON_TZ=Asia/Shanghai 0 30 12 * * *

      Run a workflow at 26, 29, and 33 minutes past every hour.

      0 26,29,33 * * * *

      CRON_TZ=Asia/Shanghai 0 26,29,33 * * * *

      Schedule a workflow to run at 12:30 every day from Monday to Friday.

      0 30 4 ? * MON-FRI

      CRON_TZ=Asia/Shanghai 0 30 12 ? * MON-FRI

      Schedule a workflow to run every 5 minutes from 12:00 to 14:00, Monday to Friday.

      0 0/5 4-6 ? * MON-FRI

      CRON_TZ=Asia/Shanghai 0 0/5 12-14 ? * MON-FRI

      Schedule a workflow to run 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 descriptions

        Field

        Value range

        Allowed special characters

        Seconds

        0–59

        Not supported

        Minutes

        0–59

        , - * /

        Hours

        0–23

        , - * /

        Day-of-month

        1–31

        , - * ? /

        Month

        1–12 or JAN–DEC

        , - * /

        Day-of-week

        1–7 or MON–SUN

        , - * ?

      • Special character descriptions

        Character

        Definition

        Example

        *

        Indicates any value in the field.

        In the Minutes field, * means the action is performed every minute.

        ,

        Indicates a list of values.

        In the Day-of-week field, MON,WED,FRI indicates Monday, Wednesday, and Friday.

        -

        Indicates a range of values.

        In the Hours field, 10-12 indicates the time range from 10:00 to 12:00 UTC.

        ?

        Indicates no specific value.

        Use this when you specify a value for either Day-of-month or Day-of-week, but not both. For example, if you specify a date in Day-of-month, use ? in the Day-of-week field.

        /

        Indicates increments. n/m indicates an increment of m starting from n.

        In the Minutes field, 3/5 runs the workflow every 5 minutes, starting at 3 minutes past the hour.

Input format

When a time-based schedule triggers a workflow, the service passes the following JSON object as input:

{
  "triggerTime": "2020-01-01T00:00:00Z",
  "triggerName": "time-trigger",
  "payload": {
    "key": "value",
    "key_int": 1
  }
}
  • triggerTime: The time when the workflow was scheduled to run. A workflow might be scheduled more than once at the specified time. You can use this value for deduplication.

  • triggerName: The name of the time-based schedule.

  • payload: The custom input that you defined in the schedule configuration. You can access values from this object in your flow definition by using an expression, such as $.payload.key. For more information, see Input and output.