fdf
This commit is contained in:
@@ -22,6 +22,11 @@ from SYS.logger import debug
|
||||
from Store._base import Store as BaseStore
|
||||
|
||||
|
||||
# Backends that failed to initialize earlier in the current process.
|
||||
# Keyed by (store_type, instance_key) where instance_key is the name used under config.store.<type>.<instance_key>.
|
||||
_FAILED_BACKEND_CACHE: Dict[tuple[str, str], str] = {}
|
||||
|
||||
|
||||
def _normalize_store_type(value: str) -> str:
|
||||
return "".join(ch.lower() for ch in str(value or "") if ch.isalnum())
|
||||
|
||||
@@ -111,6 +116,7 @@ class Store:
|
||||
self._config = config or {}
|
||||
self._suppress_debug = suppress_debug
|
||||
self._backends: Dict[str, BaseStore] = {}
|
||||
self._backend_errors: Dict[str, str] = {}
|
||||
self._load_backends()
|
||||
|
||||
def _load_backends(self) -> None:
|
||||
@@ -131,6 +137,18 @@ class Store:
|
||||
continue
|
||||
|
||||
for instance_name, instance_config in instances.items():
|
||||
backend_name = str(instance_name)
|
||||
|
||||
# If this backend already failed earlier in this process, skip re-instantiation.
|
||||
cache_key = (store_type, str(instance_name))
|
||||
cached_error = _FAILED_BACKEND_CACHE.get(cache_key)
|
||||
if cached_error:
|
||||
self._backend_errors[str(instance_name)] = str(cached_error)
|
||||
if isinstance(instance_config, dict):
|
||||
override_name = _get_case_insensitive(dict(instance_config), "NAME")
|
||||
if override_name:
|
||||
self._backend_errors[str(override_name)] = str(cached_error)
|
||||
continue
|
||||
try:
|
||||
kwargs = _build_kwargs(store_cls, str(instance_name), instance_config)
|
||||
|
||||
@@ -144,11 +162,17 @@ class Store:
|
||||
backend_name = str(kwargs.get("NAME") or instance_name)
|
||||
self._backends[backend_name] = backend
|
||||
except Exception as exc:
|
||||
err_text = str(exc)
|
||||
self._backend_errors[str(instance_name)] = err_text
|
||||
_FAILED_BACKEND_CACHE[cache_key] = err_text
|
||||
if not self._suppress_debug:
|
||||
debug(
|
||||
f"[Store] Failed to register {store_cls.__name__} instance '{instance_name}': {exc}"
|
||||
)
|
||||
|
||||
def get_backend_error(self, backend_name: str) -> Optional[str]:
|
||||
return self._backend_errors.get(str(backend_name))
|
||||
|
||||
def list_backends(self) -> list[str]:
|
||||
return sorted(self._backends.keys())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user