All Products
Search
Document Center

CloudFlow:Create a time-based schedule

Last Updated:Jul 24, 2024

Serverless Workflow.allows you to schedule workflow 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. On the Flows page, find the workflow for which you want to create a time-based schedule and click the name of the workflow in the Name column.

    workflow-name

  3. On the Details page, click the Schedule tab. In the Schedule Management section, click Create Schedule.

    image

  4. In the Create Schedule panel, configure parameters and click OK. The following table describes the parameters that you need to configure.

    Parameter

    Description

    Example

    The name of the time-based schedule.

    Enter a name for the custom time-based schedule.

    schedule-test

    Expression

    Select a mode for configuring scheduling time and specify the time rule.

    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 workflow is scheduled. Unit: minutes.

    Select Time Interval and set the time interval to 1, which indicates that the workflow 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 Enable Schedule.

    • After you create a time-based schedule, you can view it on the Schedule tab of the workflow.create-result

    • In addition, you can view the scheduled execution records of the workflow on the Executions tab of the workflow. In this example, the workflow 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 API operation for creating a time-based schedule:

    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"
    }

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 workflow 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 workflow 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 expression

      • 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 workflow based on a specific time zone, you can use the CRON_TZ expression. For example, if you want to trigger the workflow 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 daylight saving time (DST) and winter time are used in your time zone, a function is executed more frequently or less frequently when the time changes between the DST and the winter time. We recommend that you do not set the execution time to a time point when a change between DST and winter time occurs.

      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 workflow at 12:00 every day.

      0 0 4 * * *

      CRON_TZ=Asia/Shanghai 0 0 12 * * *

      Schedule the workflow 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 workflow at 12:30 every day from Monday to Friday.

      0 30 4 ? * MON-FRI

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

      Schedule the workflow 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 workflow 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

        Valid value

        Allowed special characters

        Seconds

        0 to 59

        None

        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 specifies that the workflow is executed at the 0th second of every minute.

        ,

        Indicates a 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 specifies a time range from 10:00 to 12:00 in UTC.

        ?

        Indicates an uncertain value.

        This character is used together 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.

        /

        Specifies increments. n/m indicates an increment of m starting from the position of n.

        In the minute field, 3/5 indicates that the workflow is executed every 5 minutes starting from the 3rd minute.

Input format

The time-based schedule will be performed to schedule your workflow 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 workflow is scheduled. A workflow 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 specify the input in the scheduling configuration. The workflow expands the input JSON string to the JSON dict format. You can read it in the workflow definition by using $.payload.Key. For more information, see Inputs and outputs.