mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-20 10:41:02 +02:00
Go back to response thread
This commit is contained in:
parent
f61635384e
commit
b15f956ac7
1 changed files with 6 additions and 28 deletions
|
|
@ -27,16 +27,16 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
async def start(self):
|
async def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def ASDasync_thread(self, ws, running):
|
async def async_thread(self, ws, running):
|
||||||
|
|
||||||
while running.get():
|
while running.get():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
svc, request = await asyncio.wait_for(self.q.get(), 1)
|
id, svc, request = await asyncio.wait_for(self.q.get(), 1)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ws.send_json({"error": str(e)})
|
await ws.send_json({"id": id, "error": str(e)})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
|
|
||||||
resp = await requestor.process(request)
|
resp = await requestor.process(request)
|
||||||
|
|
||||||
await ws.send_json({ "response": resp })
|
await ws.send_json({"id": id, "response": resp })
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
|
|
@ -54,26 +54,6 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
|
|
||||||
running.stop()
|
running.stop()
|
||||||
|
|
||||||
async def processor(self, ws, id, service, request):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
print(id, service, request)
|
|
||||||
|
|
||||||
requestor = self.services[service]
|
|
||||||
|
|
||||||
resp = await requestor.process(request)
|
|
||||||
|
|
||||||
await ws.send_json({"id": id, "response": resp })
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
|
|
||||||
await ws.send_json({"id": id, "error": str(e)})
|
|
||||||
|
|
||||||
async def async_thread(self, ws, running):
|
|
||||||
while running.get():
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
async def listener(self, ws, running):
|
async def listener(self, ws, running):
|
||||||
|
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
|
|
@ -96,10 +76,8 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
if "id" not in data:
|
if "id" not in data:
|
||||||
raise RuntimeError("Bad message")
|
raise RuntimeError("Bad message")
|
||||||
|
|
||||||
asyncio.create_task(
|
await self.q.put(
|
||||||
self.processor(
|
(data["id"], data["service"], data["request"])
|
||||||
ws, data["id"], data["service"], data["request"]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue