fix(swarm-worker): isolate session to /tmp/tmux-muse.sock and filter terminal slots in poller
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SESSION="swarm-worker"
|
SESSION="swarm-worker"
|
||||||
|
SOCKET_PATH="/tmp/tmux-muse.sock"
|
||||||
LOG_DIR="/home/super/Projects/NetVM/logs"
|
LOG_DIR="/home/super/Projects/NetVM/logs"
|
||||||
LOG_FILE="${LOG_DIR}/swarm-worker.log"
|
LOG_FILE="${LOG_DIR}/swarm-worker.log"
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ WORKER_CMD="python3 /home/super/Projects/NetVM/bin/swarm_worker/daemon.py"
|
|||||||
WORKER_MATCH='swarm_worker/daemon.[p]y'
|
WORKER_MATCH='swarm_worker/daemon.[p]y'
|
||||||
|
|
||||||
session_exists() {
|
session_exists() {
|
||||||
tmux has-session -t "$SESSION" 2>/dev/null
|
tmux -S "$SOCKET_PATH" has-session -t "$SESSION" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
worker_alive() {
|
worker_alive() {
|
||||||
@@ -34,21 +35,30 @@ worker_alive() {
|
|||||||
do_start() {
|
do_start() {
|
||||||
mkdir -p "$LOG_DIR"
|
mkdir -p "$LOG_DIR"
|
||||||
if session_exists; then
|
if session_exists; then
|
||||||
echo "already running (tmux session $SESSION exists)"
|
echo "already running (tmux session $SESSION exists on $SOCKET_PATH)"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
tmux new-session -d -s "$SESSION" "$WORKER_CMD >>\"$LOG_FILE\" 2>&1"
|
tmux -S "$SOCKET_PATH" new-session -d -s "$SESSION" "$WORKER_CMD >>\"$LOG_FILE\" 2>&1"
|
||||||
sleep 1
|
sleep 1
|
||||||
if worker_alive; then
|
if worker_alive; then
|
||||||
echo "started tmux session $SESSION (logging to $LOG_FILE)"
|
echo "started tmux session $SESSION on $SOCKET_PATH (logging to $LOG_FILE)"
|
||||||
else
|
else
|
||||||
echo "WARNING: session $SESSION created but worker process not detected yet"
|
echo "WARNING: session $SESSION created on $SOCKET_PATH but worker process not detected yet"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
do_stop() {
|
do_stop() {
|
||||||
|
local stopped=0
|
||||||
if session_exists; then
|
if session_exists; then
|
||||||
tmux kill-session -t "$SESSION"
|
tmux -S "$SOCKET_PATH" kill-session -t "$SESSION" 2>/dev/null || true
|
||||||
|
stopped=1
|
||||||
|
fi
|
||||||
|
# Also clean up accidental session on default socket if present
|
||||||
|
if tmux has-session -t "$SESSION" 2>/dev/null; then
|
||||||
|
tmux kill-session -t "$SESSION" 2>/dev/null || true
|
||||||
|
stopped=1
|
||||||
|
fi
|
||||||
|
if [ "$stopped" -eq 1 ]; then
|
||||||
echo "stopped tmux session $SESSION"
|
echo "stopped tmux session $SESSION"
|
||||||
else
|
else
|
||||||
echo "not running (no tmux session $SESSION)"
|
echo "not running (no tmux session $SESSION)"
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ def find_pending_slots(stale_minutes=STALE_MINUTES):
|
|||||||
created_ts = swarm.get("created_ts") or summary.get("created_ts")
|
created_ts = swarm.get("created_ts") or summary.get("created_ts")
|
||||||
for slot in swarm.get("slots", []):
|
for slot in swarm.get("slots", []):
|
||||||
status = (slot.get("status") or "").lower()
|
status = (slot.get("status") or "").lower()
|
||||||
|
if status in ("done", "failed", "killed"):
|
||||||
|
continue
|
||||||
result = slot.get("result")
|
result = slot.get("result")
|
||||||
agent = slot.get("agent_id")
|
agent = slot.get("agent_id")
|
||||||
pending = (status == "pending") or (not agent)
|
pending = (status == "pending") or (not agent)
|
||||||
|
|||||||
Reference in New Issue
Block a user