- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <[email protected]>
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import sys
|
|
|
|
from james.lib.log import get_logger
|
|
|
|
log = get_logger("subscribe")
|
|
|
|
|
|
def redis_url() -> str:
|
|
url = os.environ.get("REDIS_URL")
|
|
if url:
|
|
return url
|
|
host = os.environ.get("REDIS_HOST", "127.0.0.1")
|
|
port = os.environ.get("REDIS_PORT", "6379")
|
|
password = os.environ.get("REDIS_PASSWORD")
|
|
auth = f":{password}@" if password else ""
|
|
return f"redis://{auth}{host}:{port}/0"
|
|
|
|
|
|
def main() -> int:
|
|
channels = sys.argv[1:] or [
|
|
"james.events.system",
|
|
"james.events.mail",
|
|
"james.events.voice",
|
|
"james.decisions",
|
|
"james.actions",
|
|
"james.audit",
|
|
]
|
|
|
|
try:
|
|
import redis
|
|
except Exception as exc: # pragma: no cover - runtime guard
|
|
log.error("redis is required", exc_info=True)
|
|
return 2
|
|
|
|
r = redis.Redis.from_url(redis_url())
|
|
pubsub = r.pubsub()
|
|
pubsub.subscribe(*channels)
|
|
log.info("subscribed", channels=channels)
|
|
|
|
for message in pubsub.listen():
|
|
if message.get("type") != "message":
|
|
continue
|
|
channel = message.get("channel")
|
|
data = message.get("data")
|
|
if isinstance(channel, bytes):
|
|
channel = channel.decode("utf-8", errors="replace")
|
|
if isinstance(data, bytes):
|
|
data = data.decode("utf-8", errors="replace")
|
|
log.info("event", channel=channel, data=data)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|