Files
work-queue-api/skill/bin/wq_stale_check
Marcus A. c5be58c3c5
Some checks failed
ci / build-test-push (push) Failing after 29s
feat: add work-queue skill for Marcus and Steve
2026-04-11 14:48:08 -05:00

36 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# wq_stale_check — find in_progress items older than timeout, mark blocked
wq_stale_check() {
local timeout_minutes="${1:-30}"
local items
items=$(curl -sf "$API_URL/work?status=in_progress" | jq -r '.[] | @json' 2>/dev/null || echo "")
if [[ -z "$items" ]]; then
echo "No in_progress items found."
return 0
fi
local count=0
now_ts=$(date -u +%s)
while IFS= read -r item; do
[[ -z "$item" ]] && continue
work_id=$(echo "$item" | jq -r '.id')
updated_at=$(echo "$item" | jq -r '.updated_at')
agent=$(echo "$item" | jq -r '.assigned_agent')
age_minutes=$(( (now_ts - $(date -u -d "$updated_at" +%s 2>/dev/null || echo "$now_ts")) / 60 ))
if [[ "$age_minutes" -gt "$timeout_minutes" ]]; then
echo "Stale: $work_id ($agent, ${age_minutes}m old) — marking blocked"
curl -sf -X PATCH "$API_URL/work/$work_id" \
-H "Content-Type: application/json" \
-d "{\"status\":\"blocked\",\"notes\":\"Auto-blocked: stale for ${age_minutes} minutes (>$timeout_minutes)\"}" | jq -r '.id' > /dev/null
count=$((count + 1))
fi
done <<< "$items"
echo "Stale check complete: $count items marked blocked."
}