Land the `decnet bus` worker and `get_bus()` factory. Transport is a host-local UNIX-domain socket (0660, group=decnet); authz is the file mode. Wire framing is a tiny verb-line + 4-byte-BE length + orjson body. NATS-style wildcard topics (`*`, `>`). At-most-once, fire-and-forget — DB stays the source of truth. `FakeBus` / `NullBus` for tests and the disabled path. Cross-host federation is deferred to a future `--bridge-tcp` mode; DEBT-030 is master-only and unblocked.
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import typer
|
|
|
|
from . import utils as _utils
|
|
from .utils import console, log
|
|
|
|
|
|
def register(app: typer.Typer) -> None:
|
|
@app.command(name="bus")
|
|
def bus_cmd(
|
|
socket_path: str = typer.Option(
|
|
None, "--socket", "-s",
|
|
help="UNIX socket path (defaults to DECNET_BUS_SOCKET env var, "
|
|
"then /run/decnet/bus.sock, then ~/.decnet/bus.sock).",
|
|
),
|
|
group: str = typer.Option(
|
|
"decnet", "--group", "-g",
|
|
help="POSIX group to chown the socket to (falls back to process "
|
|
"group if the named group does not exist).",
|
|
),
|
|
heartbeat: int = typer.Option(
|
|
10, "--heartbeat", "-H",
|
|
help="Seconds between system.bus.health heartbeat events.",
|
|
),
|
|
daemon: bool = typer.Option(False, "--daemon", "-d", help="Detach to background as a daemon process."),
|
|
) -> None:
|
|
"""Run the DECNET ServiceBus worker (host-local UNIX-socket pub/sub)."""
|
|
import asyncio
|
|
from decnet.bus.factory import _default_socket_path
|
|
from decnet.bus.worker import bus_worker
|
|
|
|
resolved = socket_path or _default_socket_path()
|
|
|
|
if daemon:
|
|
log.info("bus daemonizing socket=%s", resolved)
|
|
_utils._daemonize()
|
|
|
|
log.info("bus starting socket=%s group=%s heartbeat=%ds", resolved, group, heartbeat)
|
|
console.print(f"[bold cyan]Bus starting[/] (socket: {resolved}, heartbeat: {heartbeat}s)")
|
|
|
|
try:
|
|
asyncio.run(bus_worker(resolved, group=group, heartbeat_interval=heartbeat))
|
|
except KeyboardInterrupt:
|
|
console.print("\n[yellow]Bus stopped.[/]")
|