2025-04-22 20:21:38 +01:00
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
class Flow:
|
2026-04-16 04:03:41 -04:00
|
|
|
"""
|
|
|
|
|
Runtime representation of a deployed flow process.
|
|
|
|
|
|
|
|
|
|
This class maintains internal processor states and orchestrates
|
|
|
|
|
lifecycles (start, stop) for inputs (consumers) and parameters
|
|
|
|
|
that drive data flowing across linked nodes.
|
|
|
|
|
"""
|
2025-04-22 20:21:38 +01:00
|
|
|
def __init__(self, id, flow, processor, defn):
|
|
|
|
|
|
|
|
|
|
self.id = id
|
|
|
|
|
self.name = flow
|
|
|
|
|
|
|
|
|
|
self.producer = {}
|
|
|
|
|
|
|
|
|
|
# Consumers and publishers. Is this a bit untidy?
|
|
|
|
|
self.consumer = {}
|
|
|
|
|
|
2025-09-24 13:58:34 +01:00
|
|
|
self.parameter = {}
|
2025-04-22 20:21:38 +01:00
|
|
|
|
|
|
|
|
for spec in processor.specifications:
|
|
|
|
|
spec.add(self, processor, defn)
|
|
|
|
|
|
|
|
|
|
async def start(self):
|
|
|
|
|
for c in self.consumer.values():
|
|
|
|
|
await c.start()
|
|
|
|
|
|
|
|
|
|
async def stop(self):
|
|
|
|
|
for c in self.consumer.values():
|
|
|
|
|
await c.stop()
|
|
|
|
|
|
|
|
|
|
def __call__(self, key):
|
|
|
|
|
if key in self.producer: return self.producer[key]
|
|
|
|
|
if key in self.consumer: return self.consumer[key]
|
2025-09-24 13:58:34 +01:00
|
|
|
if key in self.parameter: return self.parameter[key].value
|
2025-04-22 20:21:38 +01:00
|
|
|
return None
|