mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-20 02:31:02 +02:00
Call out to multiple services working
This commit is contained in:
parent
a243d93db6
commit
f34a52e1c1
1 changed files with 32 additions and 9 deletions
|
|
@ -20,20 +20,37 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
endpoint_path=path, auth=auth,
|
endpoint_path=path, auth=auth,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.pulsar_host=pulsar_host
|
self.q = asyncio.Queue(maxsize=10)
|
||||||
|
|
||||||
# self.text_completion = TextCompletionRequestor(
|
self.services = services
|
||||||
# )
|
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def async_thread(self, ws, running):
|
async def async_thread(self, ws, running):
|
||||||
|
|
||||||
id = str(uuid.uuid4())
|
|
||||||
|
|
||||||
while running.get():
|
while running.get():
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
try:
|
||||||
|
svc, request = await asyncio.wait_for(self.q.get(), 1)
|
||||||
|
except TimeoutError:
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
await ws.send_json({"error": str(e)})
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
print(svc, request)
|
||||||
|
|
||||||
|
requestor = self.services[svc]
|
||||||
|
|
||||||
|
resp = await requestor.process(request)
|
||||||
|
|
||||||
|
await ws.send_json({ "response": resp })
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
await ws.send_json({"error": str(e)})
|
||||||
|
|
||||||
running.stop()
|
running.stop()
|
||||||
|
|
||||||
|
|
@ -48,12 +65,18 @@ class CommandEndpoint(SocketEndpoint):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = msg.json()
|
data = msg.json()
|
||||||
|
|
||||||
|
if data["service"] not in self.services:
|
||||||
|
raise RuntimeError("Bad service")
|
||||||
|
|
||||||
|
await self.q.put(
|
||||||
|
( data["service"], data["request"] )
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
await ws.send_json({"error": str(e)})
|
await ws.send_json({"error": str(e)})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if "service" not in data:
|
|
||||||
await ws.send_json({"error": "Malformed message"})
|
|
||||||
|
|
||||||
running.stop()
|
running.stop()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue