from dataclasses import dataclass
from logging import Logger
from rid_lib.ext import Bundle
from ..infra import depends_on
from .identity import NodeIdentity
from .kobj_queue import KobjQueue
[docs]
@dataclass
class ProfileMonitor:
"""Processes changes to node profile in the config."""
log: Logger
kobj_queue: KobjQueue
identity: NodeIdentity
[docs]
@depends_on("kobj_worker", "port_manager")
def start(self):
self.process_profile()
[docs]
def process_profile(self):
"""Processes identity bundle generated from config."""
self_bundle = Bundle.generate(
rid=self.identity.rid,
contents=self.identity.profile.model_dump()
)
self.kobj_queue.push(bundle=self_bundle)
self.log.debug("Waiting for profile to be processed...")
# IMPORTANT: this waits for the identity bundle to be processed, later
# components (like the handshaker) assume this exists at runtime.
self.kobj_queue.wait()
self.log.debug("Done!")