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:
Matt Johnson 2026-05-16 20:21:34 +00:00
commit cbe9e50383
2 changed files with 15 additions and 9 deletions

View file

@ -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

View file

@ -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."""