summaryrefslogtreecommitdiff
path: root/server/apps
diff options
context:
space:
mode:
authorshihaoyue <[email protected]>2024-05-31 21:57:39 +0800
committershihaoyue <[email protected]>2024-05-31 21:57:39 +0800
commit3f3f5263587ea828a10b3c9578cd9d530bfda242 (patch)
tree271c4c1e717a8154426521ab86df0c7cd2973914 /server/apps
parent2f8aa6b66ad45a66a62e65296232f74e7cca7b5f (diff)
/task/ops orm
Diffstat (limited to 'server/apps')
-rw-r--r--server/apps/task.py28
1 files changed, 8 insertions, 20 deletions
diff --git a/server/apps/task.py b/server/apps/task.py
index 6d1c234..cac6fd1 100644
--- a/server/apps/task.py
+++ b/server/apps/task.py
@@ -179,31 +179,19 @@ def ops_task(json_data):
ops_cn = opsmap[json_data["ops"]]
id = json_data["taskid"]
- # 查询目标任务状态
- sql = """
- SELECT AGENT_ID,STATUS
- FROM %s
- WHERE TASK_ID='%s';
- """ % (MYSQL_TAB_TASK, id)
- da.cursor.execute(sql)
- data = da.cursor.fetchall()
- if len(data) == 0:
+ task = db.session.query(Task).get(id)
+ if task is None:
return {"code": 400, "msg": "任务" + id + "不存在!!"}
# 判断操作是否是逻辑上可执行的
- if data[0]["STATUS"] in ops_state[ops]:
- # 向对应代理下发控制指令
- err = deliver_task(data[0]["AGENT_ID"], "ops", ops)
+ if task.status in ops_state[ops]:
+ err = deliver_task(task.agent_id, "ops", ops)
if err is not None:
return {"code": 500, "msg": str(err)}
- task_update_status_sql = """
- UPDATE %s
- SET STATUS='%s'
- WHERE TASK_ID='%s';""" % (MYSQL_TAB_TASK, ops_state_result[ops], id)
- da.cursor.execute(task_update_status_sql)
- da.conn.commit()
- return {"code": 200, "msg": "任务" + json_data["taskid"] + "已" + ops_cn}
+ task.status = ops_state_result[ops]
+ db.session.commit()
+ return {"code": 200, "msg": "任务" + task.task_id + "已" + ops_cn}
else:
- return {"code": 400, "msg": "无法对一个" + statemap[data[0]["STATUS"]] + "的任务执行" + ops_cn + "操作"}
+ return {"code": 400, "msg": "无法对一个" + statemap[task.status] + "的任务执行" + ops_cn + "操作"}
# 查询任务列表接口