37 lines
1.9 KiB
Python
37 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Task update API"""
|
|
import json, time
|
|
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('harnessed_agent')
|
|
user_id = await get_user()
|
|
now = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
record_id = params_kw.get('id', '').strip()
|
|
if not record_id:
|
|
result['options'] = {'title': 'Error', 'message': '记录ID不能为空', 'type': 'error'}
|
|
else:
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
await sor.sqlExe("""UPDATE hermes_tasks_workflow SET workflow_id = ${workflow_id}$, task_name = ${task_name}$, task_type = ${task_type}$, skill_name = ${skill_name}$, tool_name = ${tool_name}$, parameters_json = ${parameters_json}$, depends_on = ${depends_on}$, parallel_group = ${parallel_group}$, timeout_seconds = ${timeout_seconds}$, retry_count = ${retry_count}$, order_index = ${order_index}$, updated_at = ${updated_at}$ WHERE id = ${id}$ AND user_id = ${user_id}$""", {
|
|
'id': record_id, 'user_id': user_id, 'updated_at': now,
|
|
'workflow_id': workflow_id,
|
|
'task_name': task_name,
|
|
'task_type': task_type,
|
|
'skill_name': skill_name,
|
|
'tool_name': tool_name,
|
|
'parameters_json': parameters_json,
|
|
'depends_on': depends_on,
|
|
'parallel_group': parallel_group,
|
|
'timeout_seconds': timeout_seconds,
|
|
'retry_count': retry_count,
|
|
'order_index': order_index,
|
|
})
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '更新成功', 'type': 'success'}}
|
|
|
|
except Exception as e:
|
|
result['options'] = {'title': 'Error', 'message': '更新失败: ' + str(e), 'type': 'error'}
|
|
|
|
return json.dumps(result, ensure_ascii=False)
|