You need to enable JavaScript to run this app.
Volcano Engine Function as a Service

Volcano Engine Function as a Service

Copy page
Download PDF
Asynchronous task
Configuring asynchronous tasks
Copy page
Download PDF
Configuring asynchronous tasks
The asynchronous task mode is primarily applied to long-running and compute-intensive tasks. Volcano Engine Function as a Service (veFaaS) provides the asynchronous task mode in both webserver mode and non-webserver mode. The primary difference between the two modes lies in whether the business side needs to be built on a webserver to process requests. However, the two modes do not differ significantly in terms of business scenarios. This topic describes how to enable asynchronous tasks in these modes.​
Prerequisites​
You have completed code development locally. For details, refer to Native runtime. For the webserver mode, refer to Development methods (Web applications). For the non-webserver mode, refer to Development methods (Task).​
Limits​
  • Switching between synchronous and asynchronous modes is not supported. You can select whether to enable the asynchronous task mode only during function creation. After the function is created, this configuration cannot be modified or updated.​
  • Switching between webserver and non-webserver modes for asynchronous tasks is not supported.​
  • If the QPS of your task is high, we recommend that you enable the multiple concurrent requests per instance feature, or increase the maximum number of instances for the current function.​
warning​
In non-webserver mode, a single instance can run only one task at a time (exclusive mode) by default and cannot process multiple concurrent requests.​
  • Retries are automatically performed only for system errors. User-initiated retries are not supported.​
  • The currently supported task execution duration ranges from 10 seconds to 3 hours. Specify an appropriate timeout duration based on your business requirements.​
  • When a task times out or a user terminates a task, the response of veFaaS varies slightly based on the following scenarios:​
  • In webserver mode:​
  • If the "multiple concurrent requests per instance" feature is not enabled, veFaaS will terminate requests and restart the webserver process.​
  • If the multiple concurrent requests per instance feature is enabled, veFaaS will only cancel the corresponding requests.​
warning​
Make sure that cancellation signals are handled as expected in the business logic. For example, listen to Context cancellation signals and terminate business logic execution. Otherwise, your business logic may continue to be executed after requests are canceled. As a result, resources will be wasted, or the tasks will not be stopped as expected.​
  • In non-webserver mode, veFaaS will terminate the corresponding task process.​
  • For completed tasks, the records of execution status can be retained for up to 30 days, or up to 1,000 records of execution status can be retained. The 1,000-record limit and the 30-day limit are in the OR relationship.​
  • The currently supported event trigger types include the APIG trigger and the timer trigger.​
  • The payload of an asynchronous task can be up to 128 KB.​
Enable the asynchronous task mode​
You can perform the following steps to enable the asynchronous task mode:​
  1. Enable asynchronous tasks when you create a function.​
  • Webserver mode​
  • Non-webserver mode​
  • When you create a function, select Create「Task」. As a result, asynchronous tasks will be automatically enabled.​
tip​
We recommend that you enable the logging feature. Otherwise, you will not be able to query the execution logs of historical tasks.​
  1. After you enable the asynchronous task mode, you can specify the Retries of async task parameter. The value can be set to 0 to 3. The default value is 0, which indicates that an asynchronous task will not be retried after failure.​
  1. Click Release to release the function online.​
Asynchronous task result callback​
After receiving an asynchronous invocation request, veFaaS persists the request and immediately returns a response without waiting for the request execution to complete. If you want to notify downstream services of function asynchronous execution failures, you can configure the result callback feature. After you configure the target service, when an asynchronous invocation request is executed, veFaaS automatically calls back the corresponding target service based on the execution result.​
Scenario introduction​
Asynchronous task result callbacks apply to the following scenarios:​
  • Save events that would otherwise be discarded for subsequent use.​
  • When an asynchronous task fails and still fails after being retried based on the specified policy, you may need to be promptly notified of the task failure and handle it based on your business requirements. In this case, you can configure an asynchronous task result callback to push the failure event to the target service. You can also specify the target service as another function. veFaaS will automatically push the context of failure events to this function and execute your custom error handling logic.​
  • Automatically notify downstream services of execution results​
  • After an asynchronous task is successfully executed, if you need to automatically notify downstream services of the result so that they can take further actions, you can configure the asynchronous task result callback feature. These services will perform subsequent operations accordingly. For example, if you have configured veFaaS to automatically decompress ZIP files that are uploaded to Volcano Engine Torch Object Storage (TOS) and you want to receive notifications after a ZIP file is decompressed, you can configure the asynchronous task result callback feature for the target service.​
Limits​
  • Only HTTP- or HTTPS-type webhooks can be specified as the target services for asynchronous invocation.​
  • Only one target service can be configured.​
  • Do not call back the function itself to avoid circular calls.​
  • The payload returned by an asynchronous task in webserver mode can be up to 64 KiB in size. If the upper limit is exceeded, the payload will be truncated in the callback message.​
Callback message format​
The following sample code shows the format of a callback message and the description of each parameter:​
tip​
  • The callback request is in JSON format.​
  • The requestPayload and responsePayload fields take Base64-encoded strings as values to ensure compatibility with binary or non-UTF-8 payloads.​
​
{​
"version": "1.0", // The callback message version. Fixed value: 1.0.​
"timestamp": 1733998143975, // The time when the callback is initiated, which is a timestamp that is accurate to milliseconds.​
"requestContext": { // The context of the request.​
"requestId": "e4b46cbf-b738-xmpl-8880-********", // The request ID of the asynchronous task.​
"functionName": "my-function", // The function name.​
"condition": "RetriesExhausted", // The invocation error code.​
"approximateInvokeCount": 3 // The number of times that the asynchronous task is executed. When the value is greater than 1, it indicates that veFaaS has retried your task.​
},​
"requestPayload": "eyJ0b3NfYnVja2V0IjoibXktYnVja2V0****", // Raw request payload for the submitted task (a Base64-encoded string representing raw bytes of the HTTP Request Body). This field may be absent if the request body is empty.​
"responseContext": { // The context of the response.​
"statusCode": 200, // The status code returned by the function in webserver mode. The exit code of the task in non-webserver mode.​
"revisionNumber": 1, // The function revision.​
"functionError": "Unhandled" // The task execution failure information.​
},​
"responsePayload": "ZXJyb3IgZXhlY3V0aW5nIGNvbW1hbmQgYGV4aXQgMWA6IGV4aXQgc3RhdHVzIDEsIHBsZWFzZSBjaGVjayB0aGUgbG9ncyBmb3IgbW9yZSBkZXRh****", // In Webserver mode: Raw response payload returned by the function (Base64-encoded string representing raw bytes of the response Body). In Non-Webserver mode: This field is empty or absent.​
}​
​
Configure target services for asynchronous callbacks​
  1. Log in to the veFaaS console.​
  1. In the left navigation bar, click Function. Find the function for which the asynchronous task mode is enabled and click the function name.​
  1. On the Function configuration tab of the function details page, edit the asynchronous task settings.​
  1. In the Edit configuration information panel, configure target services for asynchronous callbacks.​
  • ​
    Parameter​
    Description​
    Retries of async task​
    The number of retries for failed asynchronous tasks. Valid values: 0 to 3.​
    Asynchronous target configuration​
    Configure target services for asynchronous callbacks.​
    • Called on success: After the asynchronous task is successfully executed, the target service is invoked.​
    • Called on failure: After the asynchronous task fails to be executed, the target service is invoked.​
    warning​
    • Only HTTP- or HTTPS-type webhooks can be specified as the target services.​
    • Make sure that the configured target services can be accessed over the Virtual Private Cloud (VPC) or the public network.​
    ​
  1. Click Save to save the configuration.​
What to do next​
Submit the task and invoke the function in asynchronous mode. For details on submitting and terminating tasks, refer to Task management.​
​
Last updated: 2026.08.19 14:06:06