refactor: implement lazy loading for coordinator-api service imports
All checks were successful
API Endpoint Tests / test-api-endpoints (push) Successful in 13s
Integration Tests / test-service-integration (push) Successful in 2m17s
Python Tests / test-python (push) Successful in 8s
Security Scanning / security-scan (push) Successful in 55s

Replaced eager imports with lazy loading using __getattr__ to defer service module imports until first access. Added module mapping dictionary and dynamic import logic to reduce initial import overhead while maintaining the same public API.
This commit is contained in:
aitbc
2026-04-20 11:11:12 +02:00
parent 64770afa6a
commit 482e0be438

View File

@@ -1,8 +1,23 @@
"""Service layer for coordinator business logic."""
from .explorer import ExplorerService
from .jobs import JobService
from .marketplace import MarketplaceService
from .miners import MinerService
from importlib import import_module
__all__ = ["JobService", "MinerService", "MarketplaceService", "ExplorerService"]
_MODULE_BY_EXPORT = {
"ExplorerService": ".explorer",
"JobService": ".jobs",
"MarketplaceService": ".marketplace",
"MinerService": ".miners",
}
def __getattr__(name: str):
module_name = _MODULE_BY_EXPORT.get(name)
if module_name is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
module = import_module(module_name, __name__)
value = getattr(module, name)
globals()[name] = value
return value