#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Task Dependency 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() dependent_task_id = params_kw.get('dependent_task_id', '').strip() dependency_task_id = params_kw.get('dependency_task_id', '').strip() dependency_type = params_kw.get('dependency_type', '').strip() async with DBPools().sqlorContext(dbname) as sor: await sor.sqlExe("""INSERT INTO task_dependencies (id, user_id, workflow_id, dependent_task_id, dependency_task_id, dependency_type, created_at, updated_at) VALUES (${id}$, ${user_id}$, ${workflow_id}$, ${dependent_task_id}$, ${dependency_task_id}$, ${dependency_type}$, ${created_at}$, ${updated_at}$)""", { 'id': new_id, 'user_id': user_id, 'workflow_id': workflow_id, 'dependent_task_id': dependent_task_id, 'dependency_task_id': dependency_task_id, 'dependency_type': dependency_type, 'created_at': now, 'updated_at': now }) result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'Task Dependency创建成功', 'type': 'success'}} except Exception as e: result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'} return json.dumps(result, ensure_ascii=False)