mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-18 09:41:03 +02:00
Remove aiopulsar dependency
This commit is contained in:
parent
2c3c508cc6
commit
2f0ee1c09b
6 changed files with 47 additions and 23 deletions
|
|
@ -59,7 +59,6 @@ setuptools.setup(
|
||||||
"ibis",
|
"ibis",
|
||||||
"jsonschema",
|
"jsonschema",
|
||||||
"aiohttp",
|
"aiohttp",
|
||||||
"aiopulsar-py",
|
|
||||||
"pinecone[grpc]",
|
"pinecone[grpc]",
|
||||||
],
|
],
|
||||||
scripts=[
|
scripts=[
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ class ServiceEndpoint:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError("Timeout")
|
raise RuntimeError("Timeout")
|
||||||
|
|
||||||
|
print(resp)
|
||||||
|
|
||||||
if resp.error:
|
if resp.error:
|
||||||
print("Error")
|
print("Error")
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import queue
|
||||||
from pulsar.schema import JsonSchema
|
from pulsar.schema import JsonSchema
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ class GraphEmbeddingsStreamEndpoint(SocketEndpoint):
|
||||||
resp = await asyncio.to_thread(q.get, timeout=0.5)
|
resp = await asyncio.to_thread(q.get, timeout=0.5)
|
||||||
await ws.send_json(serialize_graph_embeddings(resp))
|
await ws.send_json(serialize_graph_embeddings(resp))
|
||||||
|
|
||||||
except TimeoutError:
|
except queue.Empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,6 @@ class Publisher:
|
||||||
|
|
||||||
id, item = self.q.get()
|
id, item = self.q.get()
|
||||||
|
|
||||||
print("THING ON Q")
|
|
||||||
|
|
||||||
if id:
|
if id:
|
||||||
producer.send(item, { "id": id })
|
producer.send(item, { "id": id })
|
||||||
else:
|
else:
|
||||||
|
|
@ -53,4 +51,3 @@ class Publisher:
|
||||||
|
|
||||||
def send(self, id, msg):
|
def send(self, id, msg):
|
||||||
self.q.put((id, msg))
|
self.q.put((id, msg))
|
||||||
print("PUT ON Q")
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import time
|
||||||
class Subscriber:
|
class Subscriber:
|
||||||
|
|
||||||
def __init__(self, pulsar_host, topic, subscription, consumer_name,
|
def __init__(self, pulsar_host, topic, subscription, consumer_name,
|
||||||
schema=None, max_size=10):
|
schema=None, max_size=100):
|
||||||
self.pulsar_host = pulsar_host
|
self.pulsar_host = pulsar_host
|
||||||
self.topic = topic
|
self.topic = topic
|
||||||
self.subscription = subscription
|
self.subscription = subscription
|
||||||
|
|
@ -16,6 +16,7 @@ class Subscriber:
|
||||||
self.q = {}
|
self.q = {}
|
||||||
self.full = {}
|
self.full = {}
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.task = threading.Thread(target=self.run)
|
self.task = threading.Thread(target=self.run)
|
||||||
|
|
@ -37,13 +38,11 @@ class Subscriber:
|
||||||
consumer_name=self.consumer_name,
|
consumer_name=self.consumer_name,
|
||||||
schema=self.schema,
|
schema=self.schema,
|
||||||
)
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
msg = consumer.receive()
|
msg = consumer.receive()
|
||||||
|
|
||||||
print("Received", msg)
|
|
||||||
|
|
||||||
# Acknowledge successful reception of the message
|
# Acknowledge successful reception of the message
|
||||||
consumer.acknowledge(msg)
|
consumer.acknowledge(msg)
|
||||||
|
|
||||||
|
|
@ -53,11 +52,20 @@ class Subscriber:
|
||||||
id = None
|
id = None
|
||||||
|
|
||||||
value = msg.value()
|
value = msg.value()
|
||||||
if id in self.q:
|
|
||||||
self.q[id].put(value)
|
|
||||||
|
|
||||||
for q in self.full.values():
|
with self.lock:
|
||||||
q.put(value)
|
|
||||||
|
if id in self.q:
|
||||||
|
try:
|
||||||
|
self.q[id].put(value, timeout=0.5)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for q in self.full.values():
|
||||||
|
try:
|
||||||
|
q.put(value, timeout=0.5)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception:", e, flush=True)
|
print("Exception:", e, flush=True)
|
||||||
|
|
@ -66,20 +74,36 @@ class Subscriber:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
def subscribe(self, id):
|
def subscribe(self, id):
|
||||||
q = queue.Queue(maxsize=self.max_size)
|
|
||||||
self.q[id] = q
|
with self.lock:
|
||||||
|
|
||||||
|
q = queue.Queue(maxsize=self.max_size)
|
||||||
|
self.q[id] = q
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def unsubscribe(self, id):
|
def unsubscribe(self, id):
|
||||||
if id in self.q:
|
|
||||||
del self.q[id]
|
with self.lock:
|
||||||
|
|
||||||
|
if id in self.q:
|
||||||
|
# self.q[id].shutdown(immediate=True)
|
||||||
|
del self.q[id]
|
||||||
|
|
||||||
def subscribe_all(self, id):
|
def subscribe_all(self, id):
|
||||||
q = queue.Queue(maxsize=self.max_size)
|
|
||||||
self.full[id] = q
|
with self.lock:
|
||||||
|
|
||||||
|
q = queue.Queue(maxsize=self.max_size)
|
||||||
|
self.full[id] = q
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def unsubscribe_all(self, id):
|
def unsubscribe_all(self, id):
|
||||||
if id in self.full:
|
|
||||||
del self.full[id]
|
with self.lock:
|
||||||
|
|
||||||
|
if id in self.full:
|
||||||
|
# self.full[id].shutdown(immediate=True)
|
||||||
|
del self.full[id]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import queue
|
||||||
from pulsar.schema import JsonSchema
|
from pulsar.schema import JsonSchema
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
@ -38,10 +39,10 @@ class TriplesStreamEndpoint(SocketEndpoint):
|
||||||
|
|
||||||
while running.get():
|
while running.get():
|
||||||
try:
|
try:
|
||||||
resp = asyncio.to_thread(q.get, timeout=0.5)
|
resp = await asyncio.to_thread(q.get, timeout=0.5)
|
||||||
await ws.send_json(serialize_triples(resp))
|
await ws.send_json(serialize_triples(resp))
|
||||||
|
|
||||||
except TimeoutError:
|
except queue.Empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue