2025-04-22 20:21:38 +01:00
|
|
|
|
2025-04-24 18:57:33 +01:00
|
|
|
from . metrics import SubscriberMetrics
|
2025-04-22 20:21:38 +01:00
|
|
|
from . subscriber import Subscriber
|
|
|
|
|
from . spec import Spec
|
|
|
|
|
|
|
|
|
|
class SubscriberSpec(Spec):
|
|
|
|
|
|
|
|
|
|
def __init__(self, name, schema):
|
|
|
|
|
self.name = name
|
|
|
|
|
self.schema = schema
|
|
|
|
|
|
|
|
|
|
def add(self, flow, processor, definition):
|
|
|
|
|
|
2025-04-24 18:57:33 +01:00
|
|
|
subscriber_metrics = SubscriberMetrics(
|
|
|
|
|
processor = flow.id, flow = flow.name, name = self.name
|
2025-04-22 20:21:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
subscriber = Subscriber(
|
2025-12-17 21:40:43 +00:00
|
|
|
backend = processor.pubsub,
|
2025-04-22 20:21:38 +01:00
|
|
|
topic = definition[self.name],
|
|
|
|
|
subscription = flow.id,
|
|
|
|
|
consumer_name = flow.id,
|
|
|
|
|
schema = self.schema,
|
2025-04-24 18:57:33 +01:00
|
|
|
metrics = subscriber_metrics,
|
2025-04-22 20:21:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Put it in the consumer map, does that work?
|
|
|
|
|
# It means it gets start/stop call.
|
|
|
|
|
flow.consumer[self.name] = subscriber
|
|
|
|
|
|