mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 17:21:02 +02:00
async & flow donw
This commit is contained in:
parent
28377de390
commit
44b1d7e508
8 changed files with 33 additions and 50 deletions
4
Makefile
4
Makefile
|
|
@ -61,6 +61,10 @@ container: update-package-versions
|
||||||
-t ${CONTAINER_BASE}/trustgraph-ocr:${VERSION} .
|
-t ${CONTAINER_BASE}/trustgraph-ocr:${VERSION} .
|
||||||
|
|
||||||
some-containers:
|
some-containers:
|
||||||
|
${DOCKER} build -f containers/Containerfile.base \
|
||||||
|
-t ${CONTAINER_BASE}/trustgraph-base:${VERSION} .
|
||||||
|
${DOCKER} build -f containers/Containerfile.flow \
|
||||||
|
-t ${CONTAINER_BASE}/trustgraph-flow:${VERSION} .
|
||||||
${DOCKER} build -f containers/Containerfile.vertexai \
|
${DOCKER} build -f containers/Containerfile.vertexai \
|
||||||
-t ${CONTAINER_BASE}/trustgraph-vertexai:${VERSION} .
|
-t ${CONTAINER_BASE}/trustgraph-vertexai:${VERSION} .
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from .. exceptions import TooManyRequests
|
||||||
from . pubsub import PulsarClient
|
from . pubsub import PulsarClient
|
||||||
from . producer import Producer
|
from . producer import Producer
|
||||||
from . consumer import Consumer
|
from . consumer import Consumer
|
||||||
|
from . metrics import ProcessorMetrics
|
||||||
|
|
||||||
default_config_queue = config_push_queue
|
default_config_queue = config_push_queue
|
||||||
|
|
||||||
|
|
@ -31,24 +32,19 @@ class AsyncProcessor:
|
||||||
# Register a pulsar client
|
# Register a pulsar client
|
||||||
self.client = PulsarClient(**params)
|
self.client = PulsarClient(**params)
|
||||||
|
|
||||||
|
# Initialise metrics, records the parameters
|
||||||
|
ProcessorMetrics(id=self.id).info({
|
||||||
|
k: str(params[k])
|
||||||
|
for k in params
|
||||||
|
if k != "id"
|
||||||
|
})
|
||||||
|
|
||||||
# The processor runs all activity in a taskgroup, it's mandatory
|
# The processor runs all activity in a taskgroup, it's mandatory
|
||||||
# that this is provded
|
# that this is provded
|
||||||
self.taskgroup = params.get("taskgroup")
|
self.taskgroup = params.get("taskgroup")
|
||||||
if self.taskgroup is None:
|
if self.taskgroup is None:
|
||||||
raise RuntimeError("Essential taskgroup missing")
|
raise RuntimeError("Essential taskgroup missing")
|
||||||
|
|
||||||
# Pubsub parameters passed in
|
|
||||||
if not hasattr(__class__, "params_metric"):
|
|
||||||
__class__.params_metric = Info(
|
|
||||||
'params', 'Parameters configuration'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Record metrics for the processor
|
|
||||||
__class__.params_metric.info({
|
|
||||||
k: str(params[k])
|
|
||||||
for k in params
|
|
||||||
})
|
|
||||||
|
|
||||||
# Get the configuration topic
|
# Get the configuration topic
|
||||||
self.config_push_queue = params.get(
|
self.config_push_queue = params.get(
|
||||||
"config_push_queue", default_config_queue
|
"config_push_queue", default_config_queue
|
||||||
|
|
@ -161,7 +157,7 @@ class AsyncProcessor:
|
||||||
# as a paramter. A processor identity ident is used as
|
# as a paramter. A processor identity ident is used as
|
||||||
# - subscriber name
|
# - subscriber name
|
||||||
# - an identifier for flow configuration
|
# - an identifier for flow configuration
|
||||||
p = cls(**args | { "taskgroup": tg, "id", ident })
|
p = cls(**args | { "taskgroup": tg, "id": ident })
|
||||||
|
|
||||||
# Start the processor
|
# Start the processor
|
||||||
await p.start()
|
await p.start()
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ from .. schema import config_request_queue, config_response_queue
|
||||||
from .. schema import config_push_queue
|
from .. schema import config_push_queue
|
||||||
from .. log_level import LogLevel
|
from .. log_level import LogLevel
|
||||||
from .. base import AsyncProcessor, Consumer, Producer
|
from .. base import AsyncProcessor, Consumer, Producer
|
||||||
|
from . metrics import ConsumerMetrics, ProducerMetrics
|
||||||
from .. base import ProcessorMetrics, ConsumerMetrics, ProducerMetrics
|
|
||||||
|
|
||||||
class Flow:
|
class Flow:
|
||||||
def __init__(self, id, flow, processor, defn):
|
def __init__(self, id, flow, processor, defn):
|
||||||
|
|
@ -30,15 +29,15 @@ class Flow:
|
||||||
if not hasattr(self, name):
|
if not hasattr(self, name):
|
||||||
setattr(self, name, defn[name])
|
setattr(self, name, defn[name])
|
||||||
|
|
||||||
for spec in self.producer_spec:
|
for spec in processor.producer_spec:
|
||||||
|
|
||||||
name, schema = spec
|
name, schema = spec
|
||||||
|
|
||||||
producer_metrics = ProducerMetrics(
|
producer_metrics = ProducerMetrics(
|
||||||
self.id, f"{flow}-{name}"
|
id, f"{flow}-{name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
producer = self.publish(
|
producer = processor.publish(
|
||||||
queue = defn[name],
|
queue = defn[name],
|
||||||
schema = schema,
|
schema = schema,
|
||||||
metrics = producer_metrics,
|
metrics = producer_metrics,
|
||||||
|
|
@ -49,18 +48,18 @@ class Flow:
|
||||||
if not hasattr(self, name):
|
if not hasattr(self, name):
|
||||||
setattr(self, name, producer)
|
setattr(self, name, producer)
|
||||||
|
|
||||||
for spec in self.consumer_spec:
|
for spec in processor.consumer_spec:
|
||||||
|
|
||||||
name, schema, handler = spec
|
name, schema, handler = spec
|
||||||
|
|
||||||
consumer_metrics = ConsumerMetrics(
|
consumer_metrics = ConsumerMetrics(
|
||||||
self.id, f"{flow}-{name}"
|
id, f"{flow}-{name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
consumer = self.subscribe(
|
consumer = processor.subscribe(
|
||||||
flow = flow_obj,
|
flow = self,
|
||||||
queue = defn[name],
|
queue = defn[name],
|
||||||
subscriber = self.id,
|
subscriber = id,
|
||||||
schema = schema,
|
schema = schema,
|
||||||
handler = handler,
|
handler = handler,
|
||||||
metrics = consumer_metrics,
|
metrics = consumer_metrics,
|
||||||
|
|
@ -72,12 +71,10 @@ class Flow:
|
||||||
consumer.name = name
|
consumer.name = name
|
||||||
consumer.flow = self
|
consumer.flow = self
|
||||||
|
|
||||||
await consumer.start()
|
|
||||||
|
|
||||||
self.consumer[name] = consumer
|
self.consumer[name] = consumer
|
||||||
|
|
||||||
if not hasattr(self, name):
|
if not hasattr(self, name):
|
||||||
setattr(flow_obj, name, consumer)
|
setattr(self, name, consumer)
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
for c in self.consumer.values():
|
for c in self.consumer.values():
|
||||||
|
|
@ -96,9 +93,6 @@ class FlowProcessor(AsyncProcessor):
|
||||||
# Initialise base class
|
# Initialise base class
|
||||||
super(FlowProcessor, self).__init__(**params)
|
super(FlowProcessor, self).__init__(**params)
|
||||||
|
|
||||||
# Initialise metrics, records the parameters
|
|
||||||
ProcessorMetrics(id=self.id).info(params)
|
|
||||||
|
|
||||||
# Register configuration handler
|
# Register configuration handler
|
||||||
self.register_config_handler(self.on_configuration)
|
self.register_config_handler(self.on_configuration)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,12 +71,12 @@ class ProcessorMetrics:
|
||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
if not hasattr(__class__, "pubsub_metric"):
|
if not hasattr(__class__, "processor_metric"):
|
||||||
__class__.pubsub_metric = Info(
|
__class__.processor_metric = Info(
|
||||||
'pubsub', 'Pub/sub configuration',
|
'processor', 'Processor configuration',
|
||||||
["id"]
|
["id"]
|
||||||
)
|
)
|
||||||
|
|
||||||
def info(self, info):
|
def info(self, info):
|
||||||
__class__.pubsub_metric.labels(id=self.id).info(info)
|
__class__.processor_metric.labels(id=self.id).info(info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,5 +101,5 @@ class Processor(FlowProcessor):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
Processor.launch(module, __doc__)
|
Processor.launch(default_ident, __doc__)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,5 +100,5 @@ class Processor(FlowProcessor):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
Processor.launch(module, __doc__)
|
Processor.launch(default_ident, __doc__)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from trustgraph.base import AsyncProcessor, Consumer, Producer
|
||||||
from . config import Configuration
|
from . config import Configuration
|
||||||
from ... base import ProcessorMetrics, ConsumerMetrics, ProducerMetrics
|
from ... base import ProcessorMetrics, ConsumerMetrics, ProducerMetrics
|
||||||
|
|
||||||
module = "config-svc"
|
default_ident = "config-svc"
|
||||||
|
|
||||||
default_request_queue = config_request_queue
|
default_request_queue = config_request_queue
|
||||||
default_response_queue = config_response_queue
|
default_response_queue = config_response_queue
|
||||||
|
|
@ -28,23 +28,12 @@ class Processor(AsyncProcessor):
|
||||||
request_queue = params.get("request_queue", default_request_queue)
|
request_queue = params.get("request_queue", default_request_queue)
|
||||||
response_queue = params.get("response_queue", default_response_queue)
|
response_queue = params.get("response_queue", default_response_queue)
|
||||||
push_queue = params.get("push_queue", default_push_queue)
|
push_queue = params.get("push_queue", default_push_queue)
|
||||||
subscriber = params.get("subscriber", default_subscriber)
|
|
||||||
id = params.get("id")
|
id = params.get("id")
|
||||||
|
|
||||||
request_schema = ConfigRequest
|
request_schema = ConfigRequest
|
||||||
response_schema = ConfigResponse
|
response_schema = ConfigResponse
|
||||||
push_schema = ConfigResponse
|
push_schema = ConfigResponse
|
||||||
|
|
||||||
ProcessorMetrics(id=id).info(
|
|
||||||
{
|
|
||||||
"subscriber": subscriber,
|
|
||||||
"request_queue": request_queue,
|
|
||||||
"request_schema": request_schema.__name__,
|
|
||||||
"response_queue": response_queue,
|
|
||||||
"response_schema": request_schema.__name__,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
super(Processor, self).__init__(
|
super(Processor, self).__init__(
|
||||||
**params | {
|
**params | {
|
||||||
"request_schema": request_schema.__name__,
|
"request_schema": request_schema.__name__,
|
||||||
|
|
@ -72,7 +61,7 @@ class Processor(AsyncProcessor):
|
||||||
self.subs = self.subscribe(
|
self.subs = self.subscribe(
|
||||||
flow = None,
|
flow = None,
|
||||||
queue = request_queue,
|
queue = request_queue,
|
||||||
subscriber = subscriber,
|
subscriber = id,
|
||||||
schema = request_schema,
|
schema = request_schema,
|
||||||
handler = self.on_message,
|
handler = self.on_message,
|
||||||
metrics = self.request_metrics,
|
metrics = self.request_metrics,
|
||||||
|
|
@ -154,5 +143,5 @@ class Processor(AsyncProcessor):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
Processor.launch(module, __doc__)
|
Processor.launch(default_ident, __doc__)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,5 +77,5 @@ class Processor(FlowProcessor):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|
||||||
Processor.launch(ident, __doc__)
|
Processor.launch(default_ident, __doc__)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue