All Products
Search
Document Center

CloudFlow:Task

Last Updated:Aug 01, 2024

This topic describes task states and provides related examples.

Overview

Task states are used to call API operations of other integrated services to complete a job. You can use task states to invoke functions, API operations of Alibaba Cloud services, or third-party services over a common protocol such as HTTP or HTTPS. In the flow definition language (FDL), you can mark the current state as a task state by using the Task label.

The following table describes the attributes of task states.

Attribute

Type

Required

Description

Example

Name

string

Yes

The name of the state.

my-state-name

Description

string

No

The description of the state.

describe it here

Type

string

Yes

The type of the state.

Task

Action

string

Yes

The action that is to be executed in the current task. The action is usually the name of an API operation of the service, or the name of an abstract action of the integrated service. The format of the value:

<Service name>:<API operation name>.

FC:InvokeFunction

TaskMode

enum

No

The mode in which the task is invoked. CloudFlow provides three modes. For more information, see Service integration modes.

  • RequestComplete

  • WaitForCustomCallback

  • WaitForSystemCallback

WaitForCustomCallback

InputConstructor

map[string]any

No

The input constructor.

See InputConstructor.

Parameters

map[string]any

No

The specifications for the parameters that are requested to invoke. The specifications correspond to the action.

The values of the parameters can be constants or follow the JSONPath format.

For more information about the specifications, see Overview.

Timeout

string

No

The timeout period of the invocation. Unit: seconds.

30

Retry

map[string]any

No

The settings of the retry policy when an error occurs.

See Error handling.

Catch

map[string]any

No

The settings of the error capture policy.

See Error handling.

OutputConstructor

map[string]any

No

The output constructor.

For more information, see the Output constructor section of the "Inputs and outputs" topic.

Next

string

No

The next state that is executed after the current state is complete. If the End attribute is true, you do not need to specify this attribute.

my-next-state

End

bool

No

Specifies whether to end the current scope.

true

Sample requests

Invoke Function Compute

You can declare that the type of a state is Task and specify the information about the function to be invoked in the Parameters section based on the specifications for invoked Function Compute parameters. For more information about the parameter specifications, see Step 2: Configure invocation parameters. Function invocations can be performed in optimized integration mode or in Alibaba Cloud OpenAPI.

Type: StateMachine
SpecVersion: v1
Name: an example of Function Compute invocation
StartAt: an example of synchronous function invocation
States:
  - Name: an example of synchronous function invocation
    Type: Task
    TaskMode: RequestComplete
    Action: FC:InvokeFunction
    Parameters:
      resourceArn: <myFunctionArn>
      invocationType: Sync
      body: <myEvent>
    Next: an example of asynchronous function invocation
  - Name: an example of asynchronous function invocation
    Type: Task
    TaskMode: RequestComplete
    Action: FC::InvokeFunction
    Parameters:
      resourceArn: acs:fc:::services/myService1.LATEST/functions/myFunction1
      invocationType: Async
      body: <myEvent>
    Retry:
      - Errors:
          - MyCustomException1
        Description: retry policy 1
        MaxAttempts: 3
        IntervalSeconds: 2
    Catch:
      - Errors:
          - MyCustomException1
        Description: capture policy 1
        OutputConstructor:
          ErrorCode: MyCustomException1
          ErrorMessage: MyCustomException1
        Next: ErrorCatchExit
    Next: SucceededExit
  - Type: Pass
    Name: ErrorCatchExit
    End: true
  - Type: Pass
    Name: SucceededExit
    End: tru

Call an API operation of an Alibaba Cloud service

Call the corresponding API operations based on the Alibaba Cloud OpenAPI specifications. Sample format of calling an API operation: ECS:DescribeInstances.

Type: StateMachine
SpecVersion: v1
Name: an example of calling an API operation of an Alibaba Cloud service
StartAt: DescribeInstances
States:
  - Type: Task
    Name: DescribeInstances
    Action: ECS:DescribeInstances
    TaskMode: RequestComplete
    Parameters:
      RegionId: cn-hangzhou
      VpcId: vpc-bp11y195luy47h8****
      VSwitchId: vsw-bp1wb297ekw7xyh****
    End: true

Invoke a third-party service over the HTTP or HTTPS protocol

Type: StateMachine
SpecVersion: v1
Name: an example of invoking a third-party service over the HTTP protocol
StartAt: an example of invoking a third-party service over the HTTP protocol
States:
  - Type: Task
    Name: an example of invoking a third-party service over the HTTP protocol
    Action: HTTP:Request
    TaskMode: RequestComplete
    Description: an example of invoking a third-party service over the HTTP protocol
    Parameters:
      url: https://www.example.com
      method: Get