A task step invokes a Function Compute function and supports retry, error catching, and input/output mappings.
Attributes
A task step invokes a Function Compute function.
A task step contains the following attributes:
type: the step type. The value task indicates that the step is a task step.name: the name of the step.resourceArn: the resource identifier. Supported types: functions, MNS queues, and Serverless workflow flow. Example:acs:fc:cn-shanghai:18807708****3420:services/fnf_test/functions/hello. Service Integration.- Optional:pattern: execution mode for the integration service. Default value:
requestResponse. Valid values:requestResponse: Waits for the task to complete before continuing.sync: Submits the task asynchronously and waits for the execution result before continuing.waitForCallback: Submits the task asynchronously and suspends the step until a callback or timeout is received.
- Optional:
timeoutSeconds: task timeout in seconds. The step times out if execution exceeds this duration. - Optional:
end: whether to continue to subsequent steps after this step completes. - Optional:
inputMappings: input mappings. The step input is passed as the function invocation event. For more information, see InvokeFunction. - Optional:
outputMappings: output mappings.$localis the function invocation result and must be in JSON format.Note If no output mappings are specified,$localis the default step output. - Optional:
errorMappings: error mappings. Valid only when an error occurs during step execution and thecatchparameter is specified. You can use the$local.causeand$local.errorvalues to map error information to the output for the next step.Note The$local.errorand$local.codevalues are reserved for the system. Thesourcefield in errorMappings must be set to these two values. Examples. TheerrorMappingsparameter is optional. If omitted, error information is unavailable in the next step. retry: retry policies. Each policy has the following attributes:errors: one or more errors from the Error definitions table.intervalSeconds: initial retry interval in seconds. Maximum: 86,400. Default: 1.maxIntervalSeconds: maximum retry interval. Maximum and default: 86,400 seconds.maxAttempts: maximum retry count. Default: 3.multiplier: multiplier applied to each successive retry interval. Default: 2.
catch: catch policies. Each policy has the following attributes:errors: one or more errors from the error definitions table.goto: destination step name.Note The destination step must be a step parallel to the current task step.
| Function execution status | HTTP status code of a Function Compute response | Function Compute response | Serverless workflow step failure (for retry and catch) | Retry |
| Not executed | 429 | ResourceExhausted |
FC.ResourceExhausted |
Yes |
| Not executed | 4xx but not 429 | ServiceNotFound, FunctionNotFound, or InvalidArgument |
FC.ServiceNotFound, FC.FunctionNotFound, or FC.InvalidArgument |
No |
| Uncertain | 500 | InternalServerError |
FC.InternalServerError |
Yes |
| Not executed | 503 | ResourceThrottled |
FC.ResourceThrottled |
Yes |
| Execution successful, with an error code returned | 200 | A custom error, including errorType |
errorType |
Determined based on business |
| Execution failed, with an error code returned | 200 | No errorType |
FC.Unknown |
Yes |
| Execution successful, with a non-JSON object returned | 200 | No errorType |
FC.InvalidOutput |
No |
FnF.ALL: matches all errors for retry or catch use cases.
Examples
- Simple task steps
The following sample flow contains a task step.
- If the input is
{"name": "function flow"}, the output is{"hello": "function flow"}. - If no input is provided or the input lacks the
namekey, the task step fails and the flow fails.
- Define the flow.
version: v1 type: flow steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:services/fnf_test/functions/helloParameters ofresourceArn:{region}: Replace with the actual region, such ascn-shanghai.{accountID}: Replace with your account ID. Find your account ID by clicking the profile picture on the Flows page of the Serverless Workflow console.
- Define the function.
import json class MyError(Exception): pass def handle(event, context): evt = json.loads(event) if "name" in evt: return { "hello": evt["name"] } else: raise MyError("My unhandled exception")
- If the input is
- Retry
This example retries a task on
MyError. If no input is provided or the input lacks thenamekey, Serverless workflow retries the task according to the retry policy.- Waits 3 seconds after the first error, then retries.
- Waits 6 seconds (
intervalSeconds x multiplier) after the second error, then retries. - Waits 12 seconds (
intervalSeconds x multiplier x multiplier) after the third error, then retries. - If the error persists after three retries,
maxAttemptsis exceeded, the task step fails, and the flow fails.
version: v1 type: flow steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:services/fnf_test/functions/hello retry: - errors: - MyError intervalSeconds: 3 maxAttempts: 3 multiplier: 2 - Catch errors
This example catches
MyErrorand jumps to thefinalstep. Because the error is caught, the flow succeeds.version: v1 type: flow steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:services/fnf_test/functions/hello catch: - errors: - MyError goto: final - type: pass name: pass1 - type: pass name: final - Catch errors with error mappings specified
This example catches
MyErrorand jumps to thefinalstep. With error mappings specified, thefinalstep can access error details. You can also useerrorMappingsto map step inputs and constants to outputs.version: v1 type: flow steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:services/fnf_test/functions/hello errorMappings: - target: errMsg source: $local.cause # This value is reserved for the system and can be used directly when an error occurs in this step. - target: errCode source: $local.error # This value is reserved for the system and can be used directly when an error occurs in this step. catch: - errors: - MyError goto: final - type: pass name: pass1 - type: pass name: finalThe
eventof the final step contains the followingEventDetail:"EventDetail": "{\"input\":{},\"local\":{\"errorCode\":\"MyError\",\"errorMsg\":\"some message\"}}",