mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-21 18:14:44 +02:00
refactor(supervisor): use adapter registry pattern
- Add _ADAPTER_REGISTRY dict for adapter class lookup - Unify adapter __init__ signatures (all take config, config_store, cursor_db_path) - NWSAdapter now accepts config_store param (unused, for signature uniformity) - Adding new adapters requires only one dict entry, no supervisor changes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
95853200b2
commit
cbe9e50383
2 changed files with 15 additions and 9 deletions
|
|
@ -20,6 +20,7 @@ from tenacity import (
|
|||
from central import __version__
|
||||
from central.adapter import SourceAdapter
|
||||
from central.config_models import AdapterConfig, RegionConfig
|
||||
from central.config_store import ConfigStore
|
||||
from central.models import Event, Geo
|
||||
from shapely.geometry import box as shapely_box, shape as shapely_shape
|
||||
|
||||
|
|
@ -196,6 +197,7 @@ class NWSAdapter(SourceAdapter):
|
|||
def __init__(
|
||||
self,
|
||||
config: AdapterConfig,
|
||||
config_store: ConfigStore,
|
||||
cursor_db_path: Path,
|
||||
) -> None:
|
||||
self.cursor_db_path = cursor_db_path
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ from central.bootstrap_config import get_settings
|
|||
from central.models import subject_for_event
|
||||
from central.stream_manager import StreamManager
|
||||
|
||||
# Adapter registry - add new adapters here
|
||||
_ADAPTER_REGISTRY: dict[str, type[SourceAdapter]] = {
|
||||
"nws": NWSAdapter,
|
||||
"firms": FIRMSAdapter,
|
||||
}
|
||||
|
||||
CURSOR_DB_PATH = Path("/var/lib/central/cursors.db")
|
||||
|
||||
# Stream subject mappings
|
||||
|
|
@ -152,16 +158,14 @@ class Supervisor:
|
|||
|
||||
def _create_adapter(self, config: AdapterConfig) -> SourceAdapter:
|
||||
"""Create an adapter instance based on config name."""
|
||||
if config.name == "nws":
|
||||
return NWSAdapter(config=config, cursor_db_path=CURSOR_DB_PATH)
|
||||
elif config.name == "firms":
|
||||
return FIRMSAdapter(
|
||||
cls = _ADAPTER_REGISTRY.get(config.name)
|
||||
if cls is None:
|
||||
raise ValueError(f"Unknown adapter type: {config.name}")
|
||||
return cls(
|
||||
config=config,
|
||||
config_store=self._config_store,
|
||||
cursor_db_path=CURSOR_DB_PATH,
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unknown adapter type: {config.name}")
|
||||
|
||||
async def _run_adapter_loop(self, state: AdapterState) -> None:
|
||||
"""Run an adapter poll loop with rate-limit aware scheduling."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue