mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-20 04:08:06 +02:00
changes. Workspace support: - Support for separate workspaces - Addition of workspace CLI support for test purposes - Massive test update - Remove many 'user' references in services - workspace now provides the same separation - Update API
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from . metrics import ConsumerMetrics
|
|
from . consumer import Consumer
|
|
from . spec import Spec
|
|
|
|
class ConsumerSpec(Spec):
|
|
def __init__(self, name: str, schema: Any, handler: Any, concurrency: int = 1) -> None:
|
|
self.name = name
|
|
self.schema = schema
|
|
self.handler = handler
|
|
self.concurrency = concurrency
|
|
|
|
def add(self, flow: Any, processor: Any, definition: dict[str, Any]) -> None:
|
|
|
|
consumer_metrics = ConsumerMetrics(
|
|
processor = flow.id, flow = flow.name, name = self.name,
|
|
)
|
|
|
|
consumer = Consumer(
|
|
taskgroup = processor.taskgroup,
|
|
flow = flow,
|
|
backend = processor.pubsub,
|
|
topic = definition["topics"][self.name],
|
|
subscriber = (
|
|
processor.id + "--" + flow.workspace + "--" +
|
|
flow.name + "--" + self.name
|
|
),
|
|
schema = self.schema,
|
|
handler = self.handler,
|
|
metrics = consumer_metrics,
|
|
concurrency = self.concurrency
|
|
)
|
|
|
|
# Consumer handle gets access to producers and other
|
|
# metadata
|
|
consumer.id = flow.id
|
|
consumer.name = self.name
|
|
consumer.flow = flow
|
|
|
|
flow.consumer[self.name] = consumer
|
|
|