import ingestor.metrics as metrics class DataSink: """Gateway egress wrapper: fans a reading out to every configured name/collection. `postgres` is unused for now — task 12 adds `update_write_status` on top of it. """ def __init__(self, data_manager, postgres, metadata: dict | None = None) -> None: self.data_manager = data_manager self.postgres = postgres self.metadata = metadata async def emit_metric(self, **kwargs) -> None: # ponytail: delegate to data_manager, it's already a SientiaMonitoring await self.data_manager.emit_metric(**kwargs) async def publish_reading(self, tag: str, value, timestamp, names: list[dict]) -> None: """Publish one MongoDB document per name entry and record its tag value metric.""" for name in names: doc = { 'tag': tag, 'name': name['tag_name'], 'model_id': name['model_id'], 'timestamp': timestamp, 'value': value, } await self.data_manager.publish(name['collection'], doc) await self.emit_metric( metric_object=metrics.OPC_TAG_VALUE, method='set', value=value, tags={ 'pod_id': self.data_manager.pod_id, 'tag_name': name['tag_name'], 'model_id': name['model_id'], }, )