Skip to content

Commit

Permalink
fix: fixed process config mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Jan 5, 2024
1 parent 1fcb443 commit 18cb6b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 5 additions & 4 deletions TrackingBackend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def trackers_position_validator(cls, value: list[TrackerConfig]) -> list[Tracker


class ConfigManager(EyeTrackConfig, FileSystemEventHandler):
# TODO: Should the callback return the manager or the config?
def __init__(self, callback: Callable[[ConfigManager, EyeTrackConfig], None] | None = None, *args, **kwargs):
# callback function will a copy of the old config, the manager will have the new config
def __init__(self, callback: Callable[[EyeTrackConfig], None] | None = None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__callback = callback
self.__logger = get_logger()
Expand All @@ -266,7 +266,8 @@ def start(self) -> ConfigManager:
)
self.__observer.start()

self.load()
# fire callbacks incase the config was modified while the server was offline
self.on_modified(FileModifiedEvent(CONFIG_FILE)) # this also loads the config
return self

def stop(self) -> None:
Expand Down Expand Up @@ -317,7 +318,7 @@ def on_modified(self, event: FileModifiedEvent) -> None:
if self.load().model_dump() != old_config:
self.__logger.info("Config update detected, calling callbacks")
if self.__callback is not None:
self.__callback(self, EyeTrackConfig(**old_config))
self.__callback(EyeTrackConfig(**old_config))

# endregion

Expand Down
6 changes: 3 additions & 3 deletions TrackingBackend/app/etvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def setup_trackers(self) -> None:
for tracker in self.trackers:
tracker.stop()

self.trackers = []
for tracker_config in self.config.trackers:
if tracker_config.enabled:
# no need to create a new tracker if we already have one with the same uuid
if tracker_config.uuid not in [tracker.uuid for tracker in self.trackers]:
self.trackers.append(Tracker(self.config, tracker_config.uuid, self.manager, self.router))
self.trackers.append(Tracker(self.config, tracker_config.uuid, self.manager, self.router))

else:
logger.error("Cannot setup trackers while ETVR is running!")

Expand Down
24 changes: 12 additions & 12 deletions TrackingBackend/app/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,17 @@ def set_affinity(self) -> None:
self.logger.info(f"affinity={cpu_list} for process `{self.name}`")
psutil.Process().cpu_affinity(cpu_list)

def on_config_modified(self, config: ConfigManager, old_config: EyeTrackConfig) -> None:
if config != old_config:
self.logger.debug(f"Config updated for process `{self.name}`")
self.debug = self.base_config.debug
self.on_config_update(self.base_config)
self.window._debug = self.base_config.debug
for tracker in self.base_config.trackers:
if tracker.uuid == self.uuid:
old_tracker = old_config.get_tracker_by_uuid(self.uuid)
if tracker != old_tracker:
self.logger.info(f"Tracker config updated for process `{self.name}`")
self.on_tracker_config_update(tracker)
def on_config_modified(self, old_config: EyeTrackConfig) -> None:
self.logger.debug(f"Config updated for process `{self.name}`")
self.debug = self.base_config.debug
self.on_config_update(self.base_config)
self.window._debug = self.base_config.debug
for tracker_config in self.base_config.trackers:
if tracker_config.uuid == self.uuid:
old_tracker = old_config.get_tracker_by_uuid(self.uuid)
if tracker_config != old_tracker:
self.logger.info(f"Tracker config updated for process `{self.name}`")
self.on_tracker_config_update(tracker_config)

# endregion

Expand All @@ -119,6 +118,7 @@ def start(self) -> None:
return

try:
self.base_config.load()
self.__shutdown_event.clear()
self.logger.info(f"Starting Process `{self.name}`")
self.__process = Process(target=self._run, name=f"{self.name}")
Expand Down

0 comments on commit 18cb6b1

Please sign in to comment.