Adds missing standard artifacts: - README.md (if missing) - AGENTS.md (AI agent contract) - PLAN.md (current sprint) - STATUS.md (where we are) - DEVELOPMENT.md (dev workflow) - DEPLOYMENT.md (deploy procedure) - TESTING.md (test strategy) - DECISIONS.md (ADR index + templates) - .github/CODEOWNERS - .github/workflows/ci.yml Preserves all existing artifacts. Refs: RugMunchMedia/fleet-template
28 lines
783 B
Python
28 lines
783 B
Python
"""Shared event bus — decouples producers from WebSocket broadcast.
|
|
|
|
Modules like x402_marketplace emit events here. main.py's WebSocket
|
|
broadcast loop reads from this bus. No circular imports.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Callable
|
|
|
|
logger = logging.getLogger("wp.event_bus")
|
|
|
|
_subscribers: list[Callable[[str, dict], None]] = []
|
|
|
|
|
|
def subscribe(fn: Callable[[str, dict], None]) -> None:
|
|
"""Register a callback for all events."""
|
|
_subscribers.append(fn)
|
|
|
|
|
|
def emit(event_type: str, data: dict) -> None:
|
|
"""Emit an event to all subscribers (fire-and-forget)."""
|
|
for fn in _subscribers:
|
|
try:
|
|
fn(event_type, data)
|
|
except Exception as e:
|
|
logger.debug(f"Event subscriber error: {e}")
|