harnessed_agent/wwwroot/api/executions_by_workflow_create.dspy

45 lines
2.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Execution create API"""
import json, uuid, 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')
new_id = str(uuid.uuid4()).replace('-', '')
workflow_id = params_kw.get('workflow_id', '').strip()
task_id = params_kw.get('task_id', '').strip()
execution_status = params_kw.get('execution_status', '').strip()
start_time = params_kw.get('start_time', '').strip()
end_time = params_kw.get('end_time', '').strip()
duration_seconds = params_kw.get('duration_seconds', '').strip()
result_json = params_kw.get('result_json', '').strip()
error_message = params_kw.get('error_message', '').strip()
retry_count = params_kw.get('retry_count', '').strip()
async with DBPools().sqlorContext(dbname) as sor:
await sor.sqlExe("""INSERT INTO executions_by_workflow (id, user_id, workflow_id, task_id, execution_status, start_time, end_time, duration_seconds, result_json, error_message, retry_count, created_at, updated_at)
VALUES (${id}$, ${user_id}$, ${workflow_id}$, ${task_id}$, ${execution_status}$, ${start_time}$, ${end_time}$, ${duration_seconds}$, ${result_json}$, ${error_message}$, ${retry_count}$, ${created_at}$, ${updated_at}$)""", {
'id': new_id, 'user_id': user_id,
'workflow_id': workflow_id,
'task_id': task_id,
'execution_status': execution_status,
'start_time': start_time,
'end_time': end_time,
'duration_seconds': duration_seconds,
'result_json': result_json,
'error_message': error_message,
'retry_count': retry_count,
'created_at': now, 'updated_at': now
})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'Execution创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
return json.dumps(result, ensure_ascii=False)