Intelligent Media Management (IMM) can process a variety of types of data. An extended period of time is required to process some types of data and the processing result cannot be immediately returned for a request. IMM provides asynchronous API operations to process such data. Most of asynchronous API operations are named in the format of CreateXXXTask
. In addition, IMM allows you to obtain task results by using message notifications.
Asynchronous IMM API operations process time-consuming requests and cannot synchronously return request results. In asynchronous processing, data processing and operations that involve many calculations are performed in the background and tasks can be scheduled to avoid affecting user experience. Asynchronous processing avoids blocking main threads and helps improve system performance.
Task process
You upload source data to Alibaba Cloud Object Storage Service (OSS).
You call an asynchronous IMM API operation in the
CreateXXXTask
format to create an asynchronous task.IMM obtains the source data from the OSS URI that you specify.
IMM writes the data processing result to the OSS URI that you specify.
IMM sends the task status in a message to the Message Service (MNS) or ApsaraMQ for RocketMQ topic that you specify.
MNS or ApsaraMQ for RocketMQ pushes the message to your service.
Task input and output
The names of the parameters for input data are generally prefixed with Source. The following parameters are supported:
SourceURI: the address of input data. Set the value to an OSS URI.
Sources: an array of multiple input URIs.
Source: the address of input data. You can use this parameter to specify multiple URIs.
The names of the parameters for output data are generally prefixed with Target. The following parameters are supported:
TargetURI: the address of output data. This parameter supports the template syntax.
TargetURIPrefix: the prefix of the addresses of output data.
Target: the address of output data. You can use this parameter to specify multiple URIs.
The input and output data must reside in the same region as IMM.
OSS URI
An Object Storage Service (OSS) URI follows the oss://<bucket>/<object>
format and uniquely identifies an object. Example: oss://test-bucket/test-object/test.docx
.
The <bucket> parameter specifies the name of an OSS bucket that resides in the same region as the IMM project. The <object> parameter specifies the full path of an object, including the file name extension.
Common invalid formats:
http://bucket.oss-cn-hangzhou.aliyuncs.com/test-object/test.docx
oss://bucket.oss-cn-hangzhou.aliyuncs.com/test-object/test.docx
TargetURI template
A TargetURI template contains some placeholders in the URI. The placeholders are replaced with actual values when the TargetURI template is used. A TargetURI template enables dynamic generation of URIs. Example: oss://{bucket}/{tags.custom}/{dirname}/{barename}.{autoext}
.
For more information, see TargetURI template .
Authorization
An asynchronous task reads input data and writes output data based on the addresses that you specify. You must authorize IMM to read input data and write output data. These permissions are specified for an IMM project. When you call the CreateProject operation to create a project, you can use the ServiceRole parameter to specify a service-link role that IMM can assume. The default role is AliyunIMMDefaultRole, which is automatically created when you activate IMM. When IMM runs an asynchronous task, IMM assumes the specified role to obtain the permissions to obtain and upload data.
Obtain the task status
Obtain the task status by using MNS or ApsaraMQ for RocketMQ
You can use Message Service (MNS) or ApsaraMQ for RocketMQ to receive notifications of IMM tasks. For more information, see Task process. For more information about the MNS notification format, see Asynchronous message examples.
MNS or ApsaraMQ for RocketMQ and IMM must be in the same region.
(Recommended) Use the Notification parameter to specify MNS or ApsaraMQ for RocketMQ configurations for receiving asynchronous message notifications
MNS: You can use the MNS field in the Notification parameter to specify the MNS endpoint and topic for receiving asynchronous message notifications.
{ "Notification": { "MNS": { "Endpoint": "The MNS endpoint", "TopicName": "The MNS topic" } } }
ApsaraMQ for RocketMQ: You can use the RocketMQ field in the Notification parameter to specify the ApsaraMQ for RocketMQ endpoint, topic, and instance for receiving asynchronous message notifications.
{ "Notification": { "RocketMQ": { "Endpoint": "The ApsaraMQ for RocketMQ endpoint", "TopicName": "The ApsaraMQ for RocketMQ topic", "InstanceId": "The ID of the ApsaraMQ for RocketMQ instance" } } }
Use the NotifyEndpoint and NotifyTopicName parameters to specify the MNS endpoint and topic for receiving asynchronous message notifications
NotifyEndpoint: the endpoint for receiving notifications. The default value is the MNS endpoint of the caller.
NotifyTopicName: the name of the MNS topic to which notifications are sent. If this parameter is not specified, no notifications are sent.
Obtain the task status by calling the GetTask operation
IMM provides the GetTask operation that you can use to query the task status.
You can repeatedly call the GetTask operation to poll the task status until the task is complete. However, this method is inefficient. If your task takes an extended period to complete, you may need to initiate a large number of GetTask calls. In this case, global throttling may be triggered, and other API calls are affected. In addition, the GetTask operation is called at a specific interval during polling. The task can be complete at any point in time during the interval. However, you cannot be aware of the task completion until the next call. On average, the latency is half the interval. Therefore, we recommend that you do not use this method to obtain the task status in the production environment.
The task information is retained for seven days after the task starts. The task information cannot be obtained after seven days.
Use tags
You can use the Tags parameter to specify tags for an asynchronous task when you call an API operation to create the task. This parameter can be used in the following scenarios:
You want to specify custom data, which is returned in MNS messages.
You can search for tasks by tag.
You want to use tags as variables in TargetURI.