VWED_server/docs/sc/任务相关.md

459 lines
9.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```markdown
## 任务相关
#### 校验任务参数
* 方法说明
校验输入参数中的 task_id 和 task_label 字段对应的数据是否在数据库中存在。
```python
async def check_task_param(param: str) -> bool
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
{
# 任务类型 id
"task_id": "12345",
# 任务名称
"task_label": "Ps2Ws"
}
```
* 输出参数
* True对应的任务数据在数据库中存在。
* False对应的任务数据在数据库中不存在或task_id和task_label同时为空。
* 异常
本方法不抛出异常。
#### 异步创建并运行一个任务
* 方法说明
本方法是非阻塞方法,将在脚本中创建一个线程,来执行天风任务的实例。
```python
async def create_wind_task(param: str) -> str
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
{
# 任务类型 id
"task_id": "12345",
# 任务名称
"task_label": "Ps2Ws",
# 指定创建的任务实例的id
"task_record_id": "04d11f4f-d17c-4a41-9cf7-67de468035f9",
# 在天风任务中定义的参数
"input_params": "{\"fromSite\":\"PS-01\"}"
}
```
**注意**`task_id` 和 `task_label` 两者必选其一。如果同时存在,将首选使用 `task_id` 字段。
**注意input_params 字段,是个 JSON 字符串。需要在脚本里将任务参数序列化为 JSON。**
* 输出参数
JSON字符串
```
{
"code": 200, # 200表示成功 -1表示失败
"msg": "" # 提示信息
}
```
* 异常
本方法不抛出异常。
#### 根据任务实例 ID 查询任务实例
* 方法说明
根据任务实例 ID 查询任务数据。
```python
async def get_task_record_by_id(task_record_id: str) -> str
```
* 输入参数
task_record_idstr 类型,是任务实例的唯一 ID。
* 输出参数
* 如存在指定 ID 的任务实例,返回 JSON 格式的字符串。
```
{
# 任务实例id
"id": "123",
# 天风任务id
"def_id": "6743",
# 天风任务名
"def_label": "agvMove",
# 任务实例状态1000运行中1001终止1002暂停1003结束1004异常结束1005重启异常1006异常中断
"status": 1000,
# 任务创建时间
"created_on": "2022-02-12 11:23:12.0",
# 任务结束时间
"ended_on": "2022-02-12 11:26:12.0",
# 任务状态描述
"state_description": "物料搬运中",
# 外部订单号
"out_order_no": "D6567812",
# 机器人Id
"agv_id": ""
}
```
* 如果不存在指定 ID 的任务实例,返回 "null"。
* 异常
本方法抛出异常。
#### 根据外部单号查询任务实例列表
* 方法说明
根据外部单号查询任务实例列表。
```python
async def get_task_record_by_agv_id(agv_id: str) -> str
```
* 输入参数
agv_idstr 类型,是机器人 ID。
* 输出参数JSON 格式的字符串):
是 JSON 数组,包含查询到的任务实例数据。
```
[{
# 任务实例id
"id": "123",
# 天风任务id
"def_id": "6743",
# 天风任务名
"def_label": "agvMove",
# 任务实例状态1000运行中1001终止1002暂停1003结束1004异常结束, 1005重启异常, 1006异常中断
"status": 1000,
# 任务创建时间
"created_on": "2022-02-12 11:23:12",
# 结束原因
"ended_reason": "运行结束",
# 任务结束时间
"ended_on": "2022-02-12 11:26:12",
# 任务状态描述
"state_description": "物料搬运中",
# 外部订单号
"out_order_no": "D6567812"
}]
```
如果不存在对应机器人的任务实例数据,返回 "[]"。
* 异常
本方法抛出异常。
#### 任务封口
* 方法说明
将VWED任务系统中指定ID的任务封口。
```python
async def mark_complete(task_id: str, auto_get_token: bool = True) -> Dict[str, Any]
```
* 输入参数
task_idstr 类型VWED任务系统任务ID。
auto_get_tokenbool 类型是否自动获取登录token默认True。
* 输出参数
返回字典类型,包含封口结果信息。
```
{
"success": True/False, # 封口是否成功
"message": "...", # 提示信息
"data": {...} # 封口结果数据(成功时)
}
```
* 异常
本方法不抛出异常。
#### 校验任务实例ID是否存在
* 方法说明
校验任务实例id是否存在。
```python
async def is_task_record_id_exist(task_record_id: str) -> bool
```
* 输入参数
task_record_idstr 类型任务实例id。
* 输出参数
* True存在。
* False不存在。
* 异常
本方法会抛出异常。
#### 校验任务名称是否存在
* 方法说明
校验任务名称是否存在。
```python
async def is_task_label_exist(task_name: str) -> bool
```
* 输入参数
task_namestr 类型,任务名称。
* 输出参数
* True存在。
* False不存在。
* 异常
本方法会抛出异常。
#### 根据查询条件获取任务实例
* 方法说明
根据参数的条件查询任务实例。
```python
async def query_task_record(param: str) -> str
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
{
# 任务类型 id
"task_id": "",
# 任务实例 id
"task_record_id": "",
# 任务实例状态1000运行中1001终止1002暂停1003结束1004异常结束1005重启异常1006异常中断
"status": "",
# 执行任务的机器人 id
"agv_id": "",
# 开始时间,需满足'yyyy-MM-dd HH:mm:ss'格式。如果该值非空,则返回创建日期大于该时间的任务实例
"start_date": "",
# 结束时间,需满足'yyyy-MM-dd HH:mm:ss'格式。如果该值非空,则返回创建日期小于该时间的任务实例
"end_date": ""
}
```
* 输出参数
是 JSON 数组,包含查询到的任务实例数据。
```
[{
# 任务实例id
"id": "123",
# 天风任务id
"def_id": "6743",
# 天风任务名
"def_label": "agvMove",
# 任务实例状态1000运行中1001终止1002暂停1003结束1004异常结束1005重启异常1006异常中断
"status": 1000,
# 任务创建时间
"created_on": "2022-02-12 11:23:12",
# 结束原因
"ended_reason": "运行结束",
# 任务结束时间
"ended_on": "2022-02-12 11:26:12",
# 任务状态描述
"state_description": "物料搬运中",
# 外部订单号
"out_order_no": "D6567812"
}]
```
如果不存在满足条件的任务实例数据,返回 "[]"。
* 异常
本方法抛出异常。
#### 接收并持久化第三方系统任务请求
* 方法说明
```python
def save_task_log(log_param: str) -> None
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
{
# 任务类型 id
"task_id": "402883a27cda555f017cda6f55ad01b6",
# 任务实例 id
"task_record_id": "04d11f4f-d17c-4a41-9cf7-67de468035f9",
# 任务块 id
"block_id": 2,
# 日志信息
"message": "[RootBp]任务开始运行task_id=402883a27cda555f017cda6f55ad01b6",
# 日志级别1正常运行2正常停止3异常中断。
"level": 1
}
```
* 输出参数
* 异常
本方法不抛出异常。
#### 创建并运行一个任务
* 方法说明
本方法是阻塞方法,可以在脚本中创建一个天风任务的实例,并在任务执行结束后返回。
```python
async def sync_create_wind_task(task_param: str) -> str
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
{
# 任务类型 id
"task_id": "12345",
# 任务名称
"task_label": "Ps2Ws",
# 指定创建的任务实例的id
"task_record_id": "04d11f4f-d17c-4a41-9cf7-67de468035f9",
# 在天风任务中定义的参数
"input_params": "{\"fromSite\":\"PS-01\"}"
}
```
**注意**`task_id` 和 `task_label` 两者必选其一。如果同时存在,将首选使用 `task_id` 字段。
**注意input_params 字段,是个 JSON 字符串。需要在脚本里将任务参数序列化为 JSON。**
* 输出参数
* "9013",任务正常结束。
* "9014",任务异常结束。
* 异常
本方法不抛出异常。
#### 终止任务
* 方法说明
本方法是非阻塞方法,可用于终止多个正在运行的天风任务实例。
```python
async def terminate_tasks(param: str) -> None
```
* 输入参数
其参数 `param` 是 JSON 字符串,结构如下:
```
[
{
# 指定创建的任务实例的id
"task_record_id": "04d11f4f-d17c-4a41-9cf7-67de468035f9"
},
{
# 指定创建的任务实例的id
"task_record_id": "04d11f4f-d17c-4a41-9cf7-67de468035fe"
}
]
```
* 输出参数
* 异常
本方法会抛出异常。
#### 查询子任务的任务id列表
* 方法说明
本方法是非阻塞方法可根据父任务的id查询所有子任务的id。
```python
async def get_children_task_record_id(record_id: str) -> str
```
* 输入参数
record_id父任务的record_id。
* 输出参数
包含子任务id的 JSON 字符串,转换成 JSON 对象之后的示例数据如下所示:
```
[
"child-58d549a4-6d4c-4e01-a327-269e3d4c1863",
"child-sdsdfvsd-qrwe-4e02-a327-269eqwcfs863"
]
```
如果不存在满足条件的子任务,返回 "[]"。
* 异常
本方法会抛出异常。
#### 设置任务优先级
* 方法说明
本方法是非阻塞方法可根据设置任务的优先级。设置前会先验证任务记录ID是否存在。
```python
async def set_task_priority(task_record_id: str, priority: int) -> None
```
* 输入参数
task_record_id任务的实例id。
priority, 任务的优先级
* 输出参数
* 异常
本方法会抛出异常。当任务记录ID不存在时会抛出包含详细错误信息的异常。