Introduction

更新时间:
复制 MD 格式

This topic describes the basics of Flow Definition Language and provides usage examples.

Basics

Flow Definition Language (FDL) defines business logic. When a flow is executed, the Serverless Workflow service executes the steps in sequence based on the flow definition. In FDL, a flow contains steps. Steps can be simple atomic steps, such as task, succeed, fail, wait, and pass. Steps can also be complex control steps, such as choice, parallel, and foreach. You can combine these steps to build complex business logic. For example, a branch of a parallel step can be a sequence of steps. If a step encounters an error during execution, FDL provides retry and catch capabilities to handle the error.

FDL steps are similar to functions in a programming language. Combining steps is similar to function invocation. Data is passed between steps using inputs and outputs. Each step uses local variables to store data. If a step contains another step, the outer step is the parent step and the inner step is the child step.

When you define a flow, you can use the following steps:
  • Use a pass step as a placeholder to plan the basic structure of the flow.
  • Use a task step to call a function in Function Compute.
  • Use a wait step to pause the execution of the flow for a specified period.
  • Use a choice step to define different execution paths.
  • Use a succeed or fail step to stop the flow early.
  • Use a parallel step to execute multiple branches in parallel.
  • Use a foreach step to process array data in parallel.

A flow has the following properties:

  • version (Required): The version of the flow. Only v1 is supported.
  • type (Required): The type of the definition. Set this to flow.
  • steps (Required): The sequence of steps in the flow. After a step is successfully executed, the next step in the sequence is executed. To end the flow early, use the end property of a step, or use a succeed or fail step.
  • inputMappings (Optional): The input mapping. The $input variable referenced in the input mapping is the Input parameter of the StartExecution API request.
  • outputMappings (Optional): The output mapping. The $local variable referenced in the output mapping is a JSON object that stores the execution result of each step in the sequence.
    Note If you do not specify an output mapping, $local is used as the final output of the flow.
  • timeoutSeconds (Optional): The timeout period for the flow, in seconds. If the execution duration of the flow exceeds the specified timeout period, the execution times out.

Examples

  • The following example flow contains a task step. This step calls a function in Function Compute.
    version: v1
    type: flow
    steps:
      - type: task
        name: hello
        resourceArn: acs:fc:{region}:{accountID}:services/fnf_test/functions/hello      
  • The following example flow contains a sequence of two steps, step1 and step4. The first step, step1, is a parent step that contains two child steps, step2 and step3.
    version: v1
    type: flow
    steps:
      - type: parallel
        name: step1
        branches:
          - steps:
            - type: pass
              name: step2
          - steps:
            - type: pass
              name: step3
      - type: pass
        name: step4       

More information

For more information about the features of Flow Definition Language, see the following topics: