Obtaining Service Tasks

Function

This API is used to obtain service tasks.

URI

GET /v1/{project_id}/services/{service_id}/tasks

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID and Name.

service_id

Yes

String

Service ID

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

state

No

String

Status of the target service task. The value can be PENDING, RECOVERING, STARTING, UPGRADING, CREATE_FAILED, START_FAILED, RUNNING, STOPPING, STOPPED, ABNORMAL, SUCCEEDED, FAILED, DELETING, FREEZING, or FROZEN. This parameter cannot be used in ModelArts Edge.

name_like

No

String

Name of the target service task. Fuzzy match is supported. This parameter cannot be used in ModelArts Edge.

id

No

String

ID of the target service task. This parameter cannot be used in ModelArts Edge.

created_since

No

Long

Start time when the target service task is created, in ms. This parameter cannot be used in ModelArts Edge.

created_until

No

Long

End time when the target service task is created, in ms. This parameter cannot be used in ModelArts Edge.

sort_dir

No

String

Sorting rule for displaying service tasks. The value can be asc (ascending order) or desc (descending order). This parameter cannot be used in ModelArts Edge.

sort_key

No

String

Sorting field for displaying service tasks. The options are name (sorted by name), created_at (sorted by creation time), and updated_at (sorted by update time). This parameter cannot be used in ModelArts Edge.

offset

No

Integer

Offset of the first displayed service task

limit

No

Integer

Number of displayed service tasks

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

count

Long

Total number of records that meet the search criteria

tasks

Array of TaskDetails objects

Number of searched service tasks

Table 4 TaskDetails

Parameter

Type

Description

id

String

Task ID

name

String

Task name

service_name

String

Service name

creator

String

Username of the task creator

project_id

String

Project ID of the task creator

description

String

Task description

service_id

String

ID of the service corresponding to a task

created_at

String

Task creation time

updated_at

String

Time when the latest task status was updated

state

String

Task status. The value can be PENDING, RECOVERING, STARTING, UPGRADING, CREATE_FAILED, START_FAILED, RUNNING, STOPPING, STOPPED, ABNORMAL, SUCCEEDED, FAILED, DELETING, FREEZING, or FROZEN.

status

String

Details about a task status (for some statuses only)

error

error object

Error information collected when the task fails to be executed

schedule_status

String

Status of a scheduled task. The value can be ACTIVATED or INACTIVATED.

schedule

TaskSchedule object

Configuration item of a scheduled task. This parameter is optional. Scheduled tasks do not support OBS input. URL input supports only RTMP and RTSP.

input

TaskInput object

Input configuration of a task. This parameter is mandatory.

output

TaskOutputForDisplay object

Output configuration of a task

config

Object

Algorithm configuration parameters specified during task running. This parameter is mandatory for some services. The value must be in JSON format. For details about the configuration items, see the description of the corresponding algorithm service. This parameter applies only to IEF. It cannot be used in ModelArts Edge.

Table 5 error

Parameter

Type

Description

code

String

Error code for an algorithm

message

String

Error information returned by an algorithm

Table 6 TaskSchedule

Parameter

Type

Description

type

String

Type of a scheduled task. This parameter is mandatory for scheduled tasks. The options are once (executed only once), daily (executed daily), weekly (executed weekly), and monthly (executed monthly). ModelArts Edge supports only once and daily.

execution_mode

String

Execution mode of a scheduled task. This parameter is mandatory for scheduled tasks. The value can be period (execution by period) or frequency (execution by frequency). ModelArts Edge supports only execution by period.

timezone

String

Time zone where a user is located. This parameter is mandatory for scheduled tasks. The value is accurate to the minute.

days_of_week

Array of integers

Days in a week when a task is executed. This parameter is mandatory only for weekly tasks. The values 1 to 7 indicate Monday to Sunday respectively.

days_of_month

Array of integers

Days in a month when a task is executed. This parameter is mandatory only for monthly tasks. The values 1 to 31 indicate the first day to the 31st day of a month.

periods

Array of periods objects

Period-based execution configuration. Use either this parameter or frequency. In this mode, at least one period must be specified.

frequency

frequency object

Frequency-based execution configuration. Use either this parameter or periods.

Table 7 periods

Parameter

Type

Description

begin_at

String

Start time of a period. This parameter is mandatory. If a scheduled task is of the once type, the value of the parameter is in the format of yyyy-MM-ddThh:mm:ss. For other scheduled task types, the value of the parameter is in the format of hh:mm:ss.

end_at

String

End time of a period. This parameter is mandatory. If a scheduled task is of the once type, the value of the parameter is in the format of yyyy-MM-ddThh:mm:ss. For other scheduled task types, the value of the parameter is in the format of hh:mm:ss.

Table 8 frequency

Parameter

Type

Description

interval

Integer

Interval between two consecutive executions. This parameter is mandatory when execution_mode is set to frequency. The value ranges from 5 to 720, in minutes.

duration

Integer

Duration for executing a single scheduled task. This parameter is mandatory when execution_mode is set to frequency. The value ranges from 5 to 720, in minutes.

begin_at

String

Start time of executions in a day. This parameter is mandatory. If a scheduled task is of the once type, the value of the parameter is in the format of yyyy-MM-ddThh:mm:ss. For other scheduled task types, the value of the parameter is in the format of hh:mm:ss.

end_at

String

End time of executions in a day. This parameter is mandatory. If a scheduled task is of the once type, the value of the parameter is in the format of yyyy-MM-ddThh:mm:ss. For other scheduled task types, the value of the parameter is in the format of hh:mm:ss.

Table 9 TaskInput

Parameter

Type

Description

type

String

Input type of a task. This parameter is mandatory. ModelArts Edge supports the following types: restful (obtains the stream request URL from the custom streaming media server through the RESTful API), url (specified file address or stream request URL), edgecamera (edge camera bound to IEF), and vcn (VCN device). IEF supports the following types: restful, url, edgecamera, vcn, obs (files stored in OBS), and vis (video streams of VIS)

data

Array of TaskInputData objects

Input details of a task. This parameter is mandatory. The configuration varies according to the input type. Multiple inputs are allowed during creation, but only one input is allowed for update.

vcn

TaskInputVcn object

VCN server. This parameter is mandatory only when the input type is vcn.

Table 10 TaskInputData

Parameter

Type

Description

stream_name

String

Name of a VIS video stream. This parameter is mandatory when the input type is vis.

bucket

String

OBS bucket name. This parameter is mandatory when the input type is obs.

path

String

OBS path. This parameter is mandatory when the input type is obs.

url

String

File URL or RESTful request URL for obtaining a video stream. This parameter is mandatory when the input type is url or restful. The value contains a maximum of 1000 characters.

headers

Object

Headers carried in the RESTful request for obtaining a video stream. This parameter is optional when the input type is restful. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed.

certificate_check

Boolean

Whether to verify the certificate of the HTTPS request. This parameter is mandatory when the input type is restful. The value can be true or false.

rtsp_path_in_response

String

Video stream address in the response body for the RESTful request. This parameter is mandatory when the input type is restful. The value contains a maximum of 1024 characters.

node_id

String

Node ID. This parameter is required only for some services when the input type is restful or vcn.

device_id

String

VCN ID. This parameter is mandatory when the input type is vcn.

stream_type

Integer

Stream type used for analysis. This parameter is optional when the input type is vcn. The value ranges from 1 to 3. The value 1 indicates primary stream, the value 2 indicates secondary stream 1, and the value 3 indicates secondary stream 2.

id

String

ID of the mounted edge device. This parameter is mandatory when the input type is edgecamera.

camera_type

String

Camera type. This parameter is applicable to ModelArts Edge. When IPC cameras are used, set this parameter to ipc.

tag

Array of Map<String,String> objects

Camera tag. This parameter is mandatory when camera_type is set to ipc. This parameter is applicable to ModelArts Edge.

Table 11 TaskInputVcn

Parameter

Type

Description

ip

String

IP address of a VCN server. This parameter is mandatory only when the input type is vcn.

port

Integer

Port number of a VCN server. This parameter is mandatory only when the input type is vcn.

username

String

Username for logging in to a VCN server. This parameter is mandatory only when the input type is vcn.

password

String

Password for logging in to a VCN server. This parameter is mandatory only when the input type is vcn.

Table 12 TaskOutputForDisplay

Parameter

Type

Description

obs

TaskOutputObs object

Configuration information when the output type is obs. This parameter cannot be used in ModelArts Edge.

dis

TaskOutputDis object

Configuration information when the output type is dis

webhook

TaskOutputWebhook object

Configuration information when the output type is webhook.

Table 13 TaskOutputObs

Parameter

Type

Description

bucket

String

OBS bucket name. This parameter is mandatory when the obs type is used.

path

String

OBS path. This parameter is mandatory when the obs type is used.

data_category

Array of strings

List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

Table 14 TaskOutputDis

Parameter

Type

Description

stream_name

String

DIS stream name. This parameter is mandatory when the dis type is used.

data_category

Array of strings

List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

stream_id

String

DIS stream ID. This parameter is applicable to ModelArts Edge.

Table 15 TaskOutputWebhook

Parameter

Type

Description

url

String

Result callback address. This parameter is mandatory when the output type is webhook.

headers

Object

Headers carried in the result callback. This parameter is mandatory when the output type is webhook. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed, and a minimum of 1 key-value pair is allowed.

data_category

Array of strings

List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

Status code: 400

Table 16 Response body parameters

Parameter

Type

Description

error_code

String

Internal service error code

error_msg

String

Error message

Status code: 404

Table 17 Response body parameters

Parameter

Type

Description

error_code

String

Internal service error code

error_msg

String

Error message

Example Requests

Query the first five service tasks. This parameter applies to both ModelArts Edge and IEF.

/v1/b722xxxxxxxxxxxxxxxxxxxxxxeb4674/services/2a2db77f-xxxx-xxxx-xxxx-608a31865313/tasks?state=RUNNING&sort_dir=created_at&sort_key=desc&offset=0&limit=100

Example Responses

Status code: 200

Service tasks are obtained.

{
  "count" : 1,
  "tasks" : [ {
    "id" : "53e4xxxxxxxxxxxxxxxxxxxxxxb55b3e",
    "name" : "task-test",
    "creator" : "user_test",
    "project_id" : "b722xxxxxxxxxxxxxxxxxxxxxxeb4674",
    "description" : "hello world",
    "service_name" : "face-detect",
    "service_id" : "2a2db77f-xxxx-xxxx-xxxx-608a31865313",
    "created_at" : "2021-01-01T00:00:00Z",
    "updated_at" : "2021-01-01T00:00:10Z",
    "state" : "RUNNING",
    "input" : {
      "type" : "url",
      "data" : [ {
        "url" : "http://xxxx"
      } ]
    },
    "output" : {
      "dis" : {
        "stream_name" : "dis-test"
      }
    },
    "config" : {
      "image_compression_ratio" : 90,
      "render_result_sw" : 0,
      "video_sampling_interval" : 1
    }
  } ]
}

Status code: 400

The request is invalid.

{
  "error_code" : "ModelArts.0101",
  "error_msg" : "Invalid argument. The param [state] should be one of [PENDING, RECOVERING, STARTING, UPGRADING, CREATE_FAILED, START_FAILED, RUNNING, STOPPING, STOPPED, ABNORMAL, SUCCEEDED, FAILED, DELETING, FREEZING, FROZEN]"
}

Status code: 404

The specified service does not exist.

{
  "error_code" : "ModelArts.3502",
  "error_msg" : "Service 2a2db77f-xxxx-xxxx-xxxx-608a31865313 does not exist."
}

Status Codes

Status Code

Description

200

Service tasks are obtained.

400

The request is invalid.

404

The specified service does not exist.

Error Codes

See Error Codes.