Abstract base for nodus channel adapters: reconnect loop, health recording, connection manager
Project description
nodus-adapter-base
Abstract base class for nodus-channels adapters.
Provides the reconnect loop, health recording, and connection management so concrete adapters (Slack, Discord, webhook, etc.) only implement the three transport-specific methods.
Status: v0.1.0 — prepared, not yet published.
Install
pip install nodus-adapter-base
Requires nodus-channels>=0.1.0.
What it provides
| Class | Purpose |
|---|---|
BaseChannelAdapter |
Abstract base with connect() retry backoff, health recording, send(), subscribe() |
ConnectionManager |
start_all(), stop_all(), health_check_all() across a ChannelRegistry |
Implementing an adapter
from nodus_channels import ChannelInfo, Message
from nodus_adapter_base import BaseChannelAdapter
class SlackAdapter(BaseChannelAdapter):
@property
def channel_id(self) -> str:
return "slack"
@property
def info(self) -> ChannelInfo:
return ChannelInfo(id="slack", display_name="Slack")
async def _do_connect(self) -> None:
# establish websocket / API connection
...
async def _do_send(self, content, peer_id, *, thread_id=None,
reply_to_id=None, attachments=None) -> str:
# send message; return message ID
return "slack-msg-id"
def _do_subscribe(self):
# return an async generator yielding Message objects
async def _gen():
...
yield message
return _gen()
Reconnect backoff
connect() retries up to max_reconnect_attempts times (default 5) using
the backoff schedule [1, 5, 30, 60, 300] seconds. Each failure is recorded
on the HealthMonitor. Raises the last exception if all attempts fail.
Health recording
Every connect(), send(), and health_check() call records success or
failure on the adapter's HealthMonitor. Access it via adapter.health_monitor.
ConnectionManager
from nodus_channels import ChannelRegistry
from nodus_adapter_base import ConnectionManager
registry = ChannelRegistry()
registry.register(SlackAdapter())
registry.register(DiscordAdapter())
manager = ConnectionManager(registry)
results = await manager.start_all() # {"slack": True, "discord": True}
health = await manager.health_check_all() # {"slack": True, "discord": False}
await manager.stop_all()
Development
cd base
pip install -e ".[dev]"
pytest tests/ -q
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nodus_adapter_base-0.1.0.tar.gz.
File metadata
- Download URL: nodus_adapter_base-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f655a051e92105dd1ae8793a4cced93816fc34b66b871c121fbbe2bbcd97836
|
|
| MD5 |
123cf92d373c9c988ab9996dd2a4240b
|
|
| BLAKE2b-256 |
2492d26cb759f505e86536d5d4e45e882ec635b7b0c9f873a98c6619ddeaf7b2
|
File details
Details for the file nodus_adapter_base-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nodus_adapter_base-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94ad24f3faa9b372def845ba2464fc98fba2154fed8f5bde883aef0c3ae01bf2
|
|
| MD5 |
457c83217093593bfdb32d409426b9fc
|
|
| BLAKE2b-256 |
b3b543da8597b3dc8569c86c345ddd1e5c7da410bf0c7436b7acf992870ab5cd
|