- 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 <noreply@anthropic.com>
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import os
|
|
import platform
|
|
import socket
|
|
import time
|
|
from typing import Any
|
|
|
|
REGISTRY_SET_KEY = "james:nodes"
|
|
REGISTRY_LAST_SEEN_KEY = "james:nodes:last_seen"
|
|
|
|
|
|
def node_name() -> str:
|
|
return os.environ.get("JAMES_NODE") or socket.gethostname()
|
|
|
|
|
|
def node_role() -> str:
|
|
return os.environ.get("JAMES_ROLE", "unknown")
|
|
|
|
|
|
def registry_payload(interval: float, docker_available: bool, gpu_available: bool) -> dict[str, Any]:
|
|
return {
|
|
"node": node_name(),
|
|
"role": node_role(),
|
|
"hostname": socket.gethostname(),
|
|
"fqdn": socket.getfqdn(),
|
|
"os": platform.system().lower(),
|
|
"arch": platform.machine().lower(),
|
|
"watcher_interval": interval,
|
|
"docker_available": docker_available,
|
|
"gpu_available": gpu_available,
|
|
"last_seen": int(time.time()),
|
|
}
|
|
|
|
|
|
def register_node(r, payload: dict[str, Any], ttl_seconds: int) -> None:
|
|
node = payload.get("node", node_name())
|
|
key = f"{REGISTRY_SET_KEY}:{node}"
|
|
pipeline = r.pipeline()
|
|
pipeline.hset(key, mapping=payload)
|
|
if ttl_seconds > 0:
|
|
pipeline.expire(key, ttl_seconds)
|
|
pipeline.sadd(REGISTRY_SET_KEY, node)
|
|
pipeline.zadd(REGISTRY_LAST_SEEN_KEY, {node: payload.get("last_seen", int(time.time()))})
|
|
pipeline.execute()
|