feat: Task 10 — AMQP connection layer with aio-pika
amqp.py: connect/disconnect/get_channel/publish with auto-reconnect - Graceful degradation when aio-pika not installed - Lazy secret file reader via config.get_amqp_url() - Fire-and-forget publish (logs error, never raises) - Connection errors caught and logged (non-fatal) config.py: AMQP_RECONNECT_DELAY, exchanges, get_amqp_url() helper app.py: connect in lifespan after assess_hardware, disconnect on shutdown requirements.txt: aio-pika>=9.0.0 tests/test_amqp.py: 3 mocked tests (publish success, publish disconnected no-raise, get_channel reconnect) 135 tests pass (132 existing + 3 new) Fixes: AGENTS.md test/run commands (venv was incomplete)
This commit is contained in:
@@ -16,6 +16,23 @@ SEARXNG_BASE = "http://localhost:8888"
|
||||
DEFAULT_MODEL = "llama3.1:latest"
|
||||
COMPLETIONS_API_KEY = os.environ.get("JARVISCHAT_COMPLETIONS_API_KEY", "jc-sk-" + os.urandom(24).hex())
|
||||
|
||||
# --- AMQP ---
|
||||
AMQP_RECONNECT_DELAY = 5
|
||||
AMQP_EXCHANGE_ADMIN = "jc.admin"
|
||||
AMQP_EXCHANGE_SYSTEM = "jc.system"
|
||||
AMQP_SECRET_PATH = "/home/gramps/.jc_amqp_secret"
|
||||
|
||||
def get_amqp_url() -> str:
|
||||
url = os.environ.get("JARVISCHAT_AMQP_URL")
|
||||
if url:
|
||||
return url
|
||||
try:
|
||||
with open(AMQP_SECRET_PATH) as f:
|
||||
pw = f.read().strip()
|
||||
except (FileNotFoundError, OSError):
|
||||
pw = "password"
|
||||
return f"amqp://jarvischat:{pw}@localhost:5672/jarvischat"
|
||||
|
||||
# --- Auth ---
|
||||
SESSION_TIMEOUT_SECONDS = 90
|
||||
MAX_PIN_ATTEMPTS = 5
|
||||
|
||||
Reference in New Issue
Block a user