"""Трекер созданных инстансов — только те что породило приложение.""" import json import os import threading _LOCK = threading.Lock() _PATH = os.path.join(os.path.dirname(__file__), "..", "instances.json") def _load(): try: with open(_PATH) as f: return json.load(f) except (FileNotFoundError, json.JSONDecodeError): return {} def _save(data): with open(_PATH, "w") as f: json.dump(data, f, indent=2) def add(instance_uid, svc_id, display_name): with _LOCK: data = _load() data[instance_uid] = { "svcId": svc_id, "displayName": display_name, "instanceUid": instance_uid, } _save(data) def remove(instance_uid): with _LOCK: data = _load() data.pop(instance_uid, None) _save(data) def list_all(): with _LOCK: return list(_load().values())