mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-05 22:15:04 +00:00
37-biomek-i5i7 (#40)
* add biomek.py demo implementation * 更新LiquidHandlerBiomek类,添加资源创建功能,优化协议创建方法,修复部分代码格式问题,更新YAML配置以支持新功能。 * Test * fix biomek success type * Convert LH action to biomek. * Update biomek.py * 注册表上报handle和schema (param input) * 修复biomek缺少的字段 * delete 's' * Remove warnings * Update biomek.py * Biomek test * Update biomek.py * 新增transfer_biomek的msg * New transfer_biomek * Updated transfer_biomek * 更新transfer_biomek的msg * 更新transfer_biomek的msg * 支持Biomek创建 * new action * fix key name typo * New parameter for biomek to run. * Refine * Update * new actions * new actions * 1 * registry * fix biomek startup add action handles * fix handles not as default entry * biomek_test.py biomek_test.py是最新的版本,运行它会生成complete_biomek_protocol.json * Update biomek.py * biomek_test.py * fix liquid_handler.biomek handles * host node新增resource add时间统计 create_resource新增handle bump version to 0.9.2 * 修正物料上传时间 改用biomek_test 增加ResultInfoEncoder 支持返回结果上传 * 正确发送return_info结果 * 同步执行状态信息 * 取消raiseValueError提示 * Update biomek_test.py * 0608 DONE * 同步了Biomek.py 现在应可用 * biomek switch back to non-test * temp disable initialize resource * Refine biomek * Refine copy issue * Refine --------- Co-authored-by: Junhan Chang <changjh@pku.edu.cn> Co-authored-by: Guangxin Zhang <guangxin.zhang.bio@gmail.com> Co-authored-by: qxw138 <qxw@stu.pku.edu.cn>
This commit is contained in:
@@ -5,7 +5,7 @@ from asyncio import get_event_loop
|
||||
from unilabos.utils.log import error
|
||||
|
||||
|
||||
def run_async_func(func, *, loop=None, **kwargs):
|
||||
def run_async_func(func, *, loop=None, trace_error=True, **kwargs):
|
||||
if loop is None:
|
||||
loop = get_event_loop()
|
||||
|
||||
@@ -17,5 +17,6 @@ def run_async_func(func, *, loop=None, **kwargs):
|
||||
error(traceback.format_exc())
|
||||
|
||||
future = asyncio.run_coroutine_threadsafe(func(**kwargs), loop)
|
||||
future.add_done_callback(_handle_future_exception)
|
||||
return future
|
||||
if trace_error:
|
||||
future.add_done_callback(_handle_future_exception)
|
||||
return future
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import collections
|
||||
import collections.abc
|
||||
import json
|
||||
from typing import get_origin, get_args
|
||||
|
||||
@@ -21,3 +21,46 @@ class TypeEncoder(json.JSONEncoder):
|
||||
return str(obj)[8:-2]
|
||||
return super().default(obj)
|
||||
|
||||
|
||||
class ResultInfoEncoder(json.JSONEncoder):
|
||||
"""专门用于处理任务执行结果信息的JSON编码器"""
|
||||
|
||||
def default(self, obj):
|
||||
# 优先处理类型对象
|
||||
if isinstance(obj, type):
|
||||
return str(obj)[8:-2]
|
||||
|
||||
# 对于无法序列化的对象,统一转换为字符串
|
||||
try:
|
||||
# 尝试调用 __dict__ 或者其他序列化方法
|
||||
if hasattr(obj, "__dict__"):
|
||||
return obj.__dict__
|
||||
elif hasattr(obj, "_asdict"): # namedtuple
|
||||
return obj._asdict()
|
||||
elif hasattr(obj, "to_dict"):
|
||||
return obj.to_dict()
|
||||
elif hasattr(obj, "dict"):
|
||||
return obj.dict()
|
||||
else:
|
||||
# 如果都不行,转换为字符串
|
||||
return str(obj)
|
||||
except Exception:
|
||||
# 如果转换失败,直接返回字符串表示
|
||||
return str(obj)
|
||||
|
||||
|
||||
def serialize_result_info(error: str, suc: bool, return_value=None) -> str:
|
||||
"""
|
||||
序列化任务执行结果信息
|
||||
|
||||
Args:
|
||||
error: 错误信息字符串
|
||||
suc: 是否成功的布尔值
|
||||
return_value: 返回值,可以是任何类型
|
||||
|
||||
Returns:
|
||||
JSON字符串格式的结果信息
|
||||
"""
|
||||
result_info = {"error": error, "suc": suc, "return_value": return_value}
|
||||
|
||||
return json.dumps(result_info, ensure_ascii=False, cls=ResultInfoEncoder)
|
||||
|
||||
Reference in New Issue
Block a user