All Products
Search
Document Center

IoT Platform:Create a batch service call task

Last Updated:Oct 15, 2024

If you want to call asynchronous services on multiple devices at a time, you can create a batch property configuration task in the IoT Platform console. This topic describes how to create a batch service call task and view information about the task. This topic also describes the topics that are used during the execution of the task and the corresponding message formats.

Prerequisites

  • A Thing Specification Language (TSL) model is defined for a product to which the devices whose asynchronous services you want to call belong and the asynchronous services have the same identifier. For more information, see Batch add TSL features.

  • The TSL service call functionality is configured for the devices. For more information, see Overview.

Task management process

  1. Create a batch service call task.

    1. In the IoT Platform console, find the instance that you want to manage and click the instance name. In the left-side navigation pane of the Instance Details page, choose Maintenance > Tasks. On the Tasks page, click Create Task.
    2. On the Create Task page, configure the parameters in the Create Task and Task Configuration steps as prompted and click Complete. Move the pointer over the 帮助 icon next to a parameter to view information about the parameter. The following table describes the parameters.

      • Create Task

        Parameter

        Description

        Task Name

        Specify a valid name for the task. You can specify a custom name.

        Task Type

        Set the parameter to Batch Service Call Task.

        Task Description

        Specify information such as the purpose of the task, which can be used to identify tasks.

        Destination Device, Product, or Group

        Select the devices for which you want to execute the task. You can select separate devices, devices by product, or devices by group.
        Important If you select devices by group, you cannot select a dynamic group.

        Task Execution Rules Issued to Devices

        Upload a rule file. The file must be in the JSON format and cannot exceed 64 KB in size.

        You can click Download Template to obtain a rule template.

        The following sample code defines a TSL service whose name is Data Computing, whose identifier is Operation_Service, whose Invoke Method parameter is Asynchronous, and whose input parameters are NumberA and NumberB, which are of the int32 data type:

        {
            "serviceIdentifier": "Operation_Service",
            "params": {
                "NumberA": 32,
                "NumberB": 56
            }
        }
        • serviceIdentifier: specifies the unique identifier of the service. To view the service identifier of a device, go to the Define Feature tab of the product to which the device belongs in the IoT Platform console.

          If a service whose identifier is Operation_Service belongs to a custom module named testFb, set the key-value pair to "serviceIdentifier": "testFb:Operation_Service". The custom module is not the default module.

        • params: specifies the input parameter of the service. You can configure multiple input parameters for params.

      • Task Configuration
        ParameterDescription
        Task Execution RateSpecify the number of times that you want to push the task per minute based on your business requirements. This parameter is required.
        Task Execution Timeout PeriodThis parameter is available only for custom tasks. You do not need to configure this parameter.
        Task Scheduling TimeThis parameter is optional.

        The system executes the task a specific period of time after the time that you specify for the Task Scheduling Time parameter.

        After you create the task, the system initiates the task but does not execute the task until the execution time is reached.

  2. After you create the task, IoT Platform calls the InvokeThingService or InvokeThingsService operation to call the service and asynchronously pushes a request to a specified device. Then, the device asynchronously returns a response to IoT Platform.

    Sample message:

    {
        "id": "123",
        "version": "1.0",
        "params": {
            "Power": "on",
            "WF": "2"
        },
        "method": "thing.service.${tsl.service.identifier}"
    }

    params contains the same data as params in the rule file. {tsl.service.identifier} contains the same value as serviceIdentifier in the rule file. In this example, the following message is used:

    {
      "id": "123",
      "version": "1.0",
      "params": {
        "NumberA": 32,
        "NumberB": 56
      },
      "method": "thing.service.Operation_Service"
    }

    For more information about the corresponding usage notes in the Alink protocol, see Call device services in asynchronous mode.

  3. In the IoT Platform console, find the instance to which the task belongs and click the instance name. On the Instance Details page, choose Maintenance > Tasks. On the Tasks page, you can view the relevant details, including the status of the task that you created.
    Important If a task is in the Timed Out state, the task can no longer be executed based on the specified schedule.

    If the sub-tasks of a task fail to be executed within seven days after the time when the task was created, the task enters the Timed Out state.

    You can perform one of the following operations based on your business requirements:

    • On the Tasks page, cancel a task that is in the Processing state.
    • Find the task that you want to manage and click View in the Actions column. On the task details page, view the task information and task statistics.
      TabDescription
      Task InformationYou can view the task information, modify the task description and task configuration, and download the rule file.
      Task SummaryYou can view statistics on sub-tasks by status.
      • Find the device that you want to manage and click View to go to the device details page.
        • On the Task tab, you can view all tasks of the device.
        • On the Device Log tab, click View. On the Device Log page, click Cloud run log. On the Cloud run log tab, select Cloud-to-device Message from the workload type drop-down list in the search bar to view task-related logs.
      • If a sub-task fails to be executed, click Execution details in the Actions column to view the cause of the failure.
      • If a sub-task times out or fails to be executed, click Timed Out or Failed in the Status column to view the sub-tasks in the corresponding state.

        In the upper part of the Tasks page, click Rerun to re-execute the sub-tasks that are in the Timed Out and Failed states of the current task.

    • Click Delete in the Actions column of a task. In the message that appears, click OK.
      Warning After you delete a task, all data that is related to the task is deleted. If business applications run based on the task, the applications may become unavailable and your business may be affected. Proceed with caution.