Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""只含业务处理函数;协议和类型验证由 SDK 承担。"""
|
||||
import asyncio
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, sys.argv[2])
|
||||
from dever_component import BusinessError, Worker, main
|
||||
|
||||
|
||||
async def echo(value, setting):
|
||||
return dict(out=value["value"], name=value["label"])
|
||||
|
||||
|
||||
async def fail(value, setting):
|
||||
raise BusinessError("demo.service.port.Error.Rejected", dict(message="business rejection"))
|
||||
|
||||
|
||||
async def hang(value, setting):
|
||||
marker = pathlib.Path(setting["marker"])
|
||||
marker.touch()
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
marker.with_suffix(".stopped").touch()
|
||||
|
||||
|
||||
async def invalid(value, setting):
|
||||
return dict(out=200)
|
||||
|
||||
|
||||
async def raw(value, setting):
|
||||
return dict(out=value["value"])
|
||||
|
||||
async def floating(value, setting):
|
||||
return dict(out=value["value"] + 0.25)
|
||||
|
||||
async def tool(value, setting):
|
||||
return dict(out=value["value"])
|
||||
|
||||
|
||||
manifest = json.loads(pathlib.Path(sys.argv[1]).read_text())
|
||||
main(Worker(manifest, dict(echo=echo, fail=fail, hang=hang, invalid=invalid, raw=raw, floating=floating, tool=tool)))
|
||||
Reference in new issue
Block a user