mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
Merge pull request #382 from trustgraph-ai/fix/import-queues-not-working
Fix/import queues not working
This commit is contained in:
commit
6dc7b4cbfc
5 changed files with 36 additions and 26 deletions
|
|
@ -22,6 +22,9 @@ class DocumentEmbeddingsImport:
|
||||||
pulsar_client, topic = queue, schema = DocumentEmbeddings
|
pulsar_client, topic = queue, schema = DocumentEmbeddings
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def start(self):
|
||||||
|
await self.publisher.start()
|
||||||
|
|
||||||
async def destroy(self):
|
async def destroy(self):
|
||||||
self.running.stop()
|
self.running.stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ class GraphEmbeddingsImport:
|
||||||
pulsar_client, topic = queue, schema = GraphEmbeddings
|
pulsar_client, topic = queue, schema = GraphEmbeddings
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def start(self):
|
||||||
|
await self.publisher.start()
|
||||||
|
|
||||||
async def destroy(self):
|
async def destroy(self):
|
||||||
self.running.stop()
|
self.running.stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,8 @@ class DispatcherManager:
|
||||||
queue = qconfig,
|
queue = qconfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await dispatcher.start()
|
||||||
|
|
||||||
return dispatcher
|
return dispatcher
|
||||||
|
|
||||||
async def process_flow_export(self, ws, running, params):
|
async def process_flow_export(self, ws, running, params):
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ class TriplesImport:
|
||||||
pulsar_client, topic = queue, schema = Triples
|
pulsar_client, topic = queue, schema = Triples
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def start(self):
|
||||||
|
await self.publisher.start()
|
||||||
|
|
||||||
async def destroy(self):
|
async def destroy(self):
|
||||||
self.running.stop()
|
self.running.stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,39 +10,42 @@ import pytesseract
|
||||||
from pdf2image import convert_from_bytes
|
from pdf2image import convert_from_bytes
|
||||||
|
|
||||||
from ... schema import Document, TextDocument, Metadata
|
from ... schema import Document, TextDocument, Metadata
|
||||||
from ... schema import document_ingest_queue, text_ingest_queue
|
from ... base import FlowProcessor, ConsumerSpec, ProducerSpec
|
||||||
from ... log_level import LogLevel
|
|
||||||
from ... base import ConsumerProducer
|
|
||||||
|
|
||||||
module = "ocr"
|
default_ident = "pdf-decoder"
|
||||||
|
|
||||||
default_input_queue = document_ingest_queue
|
class Processor(FlowProcessor):
|
||||||
default_output_queue = text_ingest_queue
|
|
||||||
default_subscriber = module
|
|
||||||
|
|
||||||
class Processor(ConsumerProducer):
|
|
||||||
|
|
||||||
def __init__(self, **params):
|
def __init__(self, **params):
|
||||||
|
|
||||||
input_queue = params.get("input_queue", default_input_queue)
|
id = params.get("id", default_ident)
|
||||||
output_queue = params.get("output_queue", default_output_queue)
|
|
||||||
subscriber = params.get("subscriber", default_subscriber)
|
|
||||||
|
|
||||||
super(Processor, self).__init__(
|
super(Processor, self).__init__(
|
||||||
**params | {
|
**params | {
|
||||||
"input_queue": input_queue,
|
"id": id,
|
||||||
"output_queue": output_queue,
|
|
||||||
"subscriber": subscriber,
|
|
||||||
"input_schema": Document,
|
|
||||||
"output_schema": TextDocument,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.register_specification(
|
||||||
|
ConsumerSpec(
|
||||||
|
name = "input",
|
||||||
|
schema = Document,
|
||||||
|
handler = self.on_message,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.register_specification(
|
||||||
|
ProducerSpec(
|
||||||
|
name = "output",
|
||||||
|
schema = TextDocument,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
print("PDF OCR inited")
|
print("PDF OCR inited")
|
||||||
|
|
||||||
async def handle(self, msg):
|
async def on_message(self, msg, consumer, flow):
|
||||||
|
|
||||||
print("PDF message received")
|
print("PDF message received", flush=True)
|
||||||
|
|
||||||
v = msg.value()
|
v = msg.value()
|
||||||
|
|
||||||
|
|
@ -65,19 +68,15 @@ class Processor(ConsumerProducer):
|
||||||
text=text.encode("utf-8"),
|
text=text.encode("utf-8"),
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.send(r)
|
await flow("output").send(r)
|
||||||
|
|
||||||
print("Done.", flush=True)
|
print("Done.", flush=True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_args(parser):
|
def add_args(parser):
|
||||||
|
FlowProcessor.add_args(parser)
|
||||||
ConsumerProducer.add_args(
|
|
||||||
parser, default_input_queue, default_subscriber,
|
|
||||||
default_output_queue,
|
|
||||||
)
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
Processor.launch(module, __doc__)
|
Processor.launch(default_ident, __doc__)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue