mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-22 02:24:38 +02:00
refactor(adapter): add abstract apply_config method
SourceAdapter now requires apply_config() for hot-reload support. Each adapter implements its own config extraction from settings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
12a66d45ba
commit
1ea56b67fd
1 changed files with 15 additions and 1 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import AsyncIterator
|
from collections.abc import AsyncIterator
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from central.config_models import AdapterConfig
|
||||||
|
|
||||||
from central.models import Event
|
from central.models import Event
|
||||||
|
|
||||||
|
|
@ -15,7 +19,6 @@ class SourceAdapter(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str # short identifier, e.g. "nws"
|
name: str # short identifier, e.g. "nws"
|
||||||
cadence_s: int # seconds between poll() calls
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def poll(self) -> AsyncIterator[Event]:
|
async def poll(self) -> AsyncIterator[Event]:
|
||||||
|
|
@ -26,6 +29,17 @@ class SourceAdapter(ABC):
|
||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def apply_config(self, new_config: "AdapterConfig") -> None:
|
||||||
|
"""
|
||||||
|
Apply new configuration to the adapter.
|
||||||
|
|
||||||
|
Called by supervisor when config changes via hot-reload.
|
||||||
|
The adapter should extract relevant settings from
|
||||||
|
new_config.settings and update its internal state.
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
async def startup(self) -> None:
|
async def startup(self) -> None:
|
||||||
"""Optional lifecycle hook called before first poll."""
|
"""Optional lifecycle hook called before first poll."""
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue