-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstatus-loop.sh
More file actions
executable file
·57 lines (51 loc) · 1.58 KB
/
Copy pathstatus-loop.sh
File metadata and controls
executable file
·57 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Root agent status loop: append agent status to MESSAGE-BUS.md every 60 seconds.
set -euo pipefail
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
RUNS_DIR="${RUNS_DIR:-$BASE_DIR/runs}"
BUS="${MESSAGE_BUS:-$BASE_DIR/MESSAGE-BUS.md}"
LOG="$RUNS_DIR/status-loop.log"
while true; do
ts=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
msg_id="MSG-$(date -u +%Y%m%d-%H%M%S)-orchestrator-status-loop"
running=()
finished=()
unknown=()
while IFS= read -r -d '' run_dir; do
run_name=$(basename "$run_dir")
pid_file="$run_dir/pid.txt"
if [ -f "$pid_file" ]; then
pid=$(cat "$pid_file" 2>/dev/null || true)
if [ -n "$pid" ] && ps -p "$pid" >/dev/null 2>&1; then
running+=("$run_name:$pid")
else
finished+=("$run_name:$pid")
fi
continue
fi
if rg -q "EXIT_CODE=" "$run_dir/run-info.txt" 2>/dev/null; then
finished+=("$run_name:exit")
else
unknown+=("$run_name:unknown")
fi
done < <(find "$RUNS_DIR" -maxdepth 1 -type d -name "run_*" -print0 2>/dev/null)
run_count=${#running[@]}
fin_count=${#finished[@]}
unk_count=${#unknown[@]}
running_list="none"
if [ "$run_count" -gt 0 ]; then
running_list=$(printf "%s " "${running[@]}" | sed 's/ $//')
fi
{
echo "---"
echo "messageId: $msg_id"
echo "type: PROGRESS"
echo "agent: orchestrator-root-0"
echo "timestamp: $ts"
echo "runId: N/A"
echo "taskId: TASK-STATUS-LOOP"
echo "---"
echo "Agent status: running=$run_count finished=$fin_count unknown=$unk_count running_list=[$running_list]"
} | tee -a "$BUS" >>"$LOG"
sleep 60
done