connector: wanted(port) says whether anyone watches or reads a port

This commit is contained in:
Melvin Strobl
2026-10-27 15:20:24 +01:00
parent 7b453af3fe
commit 00cda9d2f1
4 changed files with 68 additions and 0 deletions
+14
View File
@@ -21,6 +21,8 @@ What a connector gets from the base class:
* :meth:`ConnectorNode.save_artifact`, for a device whose readings are bytes —
a camera frame, a recorded clip — which travel as a reference on a media
port rather than as the message itself;
* :meth:`ConnectorNode.wanted`, so a camera fetches frames only while someone
watches them or a running flow reads them;
* :attr:`ConnectorNode.store`, for the few short strings that have to outlive
a restart — a certificate pinned on first contact, a pairing token — shared
by every node of the connector's package; :mod:`fluksio.flow.connector_tls`
@@ -40,6 +42,7 @@ from typing import TYPE_CHECKING, Any, ClassVar
from pydantic import BaseModel, Field
from fluksio.flow.connector_store import ConnectorStore, namespace_of
from fluksio.flow.demand import demand
from fluksio.flow.nodes import Node
if TYPE_CHECKING:
@@ -173,6 +176,17 @@ class ConnectorNode(Node):
[data], name=name, media_type=media_type, volatile=volatile
)
def wanted(self, port: str) -> bool:
"""Whether anyone wants what ``port`` publishes right now.
A dashboard tile on screen, a screen through the portal, or a node of a
running flow reading the port's message. A camera asks before each
frame, so it sends nothing while nobody watches. Always true on a
remote worker, which cannot see who watches.
"""
names = {s.name for s in self.output_ports if s.port == port and s.name}
return demand.wants(names)
@property
def store(self) -> ConnectorStore:
"""Short strings this connector keeps across restarts.