From 2a1c974c92ff3ba459428377e0856b47b93cba7c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 10 Apr 2026 07:36:58 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20bug:=20supervisor=20preflight=20uses=20d?= =?UTF-8?q?irect=20`wpdb`=20SQL=20=E2=80=94=20should=20use=20existing=20`w?= =?UTF-8?q?oodpecker=5Fapi()`=20helper=20(#541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervisor/preflight.sh | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/supervisor/preflight.sh b/supervisor/preflight.sh index e9e4de2..6d12cfd 100755 --- a/supervisor/preflight.sh +++ b/supervisor/preflight.sh @@ -146,27 +146,24 @@ done echo "## CI Pipelines (${PROJECT_NAME})" -_recent_ci=$(wpdb -A -c " - SELECT number, status, branch, - ROUND(EXTRACT(EPOCH FROM (to_timestamp(finished) - to_timestamp(started)))/60)::int as dur_min - FROM pipelines - WHERE repo_id = ${WOODPECKER_REPO_ID} - AND finished > 0 - AND to_timestamp(finished) > now() - interval '24 hours' - ORDER BY number DESC LIMIT 10;" 2>/dev/null || echo "CI database query failed") +# Fetch pipelines via Woodpecker REST API (database-driver-agnostic) +_pipelines=$(woodpecker_api "/repos/${WOODPECKER_REPO_ID}/pipelines?perPage=50" 2>/dev/null || echo '[]') +_now=$(date +%s) + +# Recent pipelines (finished in last 24h = 86400s), sorted by number DESC +_recent_ci=$(echo "$_pipelines" | jq -r --argjson now "$_now" ' + [.[] | select(.finished > 0) | select(($now - .finished) < 86400)] + | sort_by(-.number) | .[0:10] + | .[] | "\(.number)\t\(.status)\t\(.branch)\t\((.finished - .started) / 60 | floor)"' 2>/dev/null || echo "CI query failed") echo "$_recent_ci" -_stuck=$(wpdb -c " - SELECT count(*) FROM pipelines - WHERE repo_id=${WOODPECKER_REPO_ID} - AND status='running' - AND EXTRACT(EPOCH FROM now() - to_timestamp(started)) > 1200;" 2>/dev/null | xargs || echo "?") +# Stuck: running pipelines older than 20min (1200s) +_stuck=$(echo "$_pipelines" | jq --argjson now "$_now" ' + [.[] | select(.status == "running") | select(($now - .started) > 1200)] | length' 2>/dev/null || echo "?") -_pending=$(wpdb -c " - SELECT count(*) FROM pipelines - WHERE repo_id=${WOODPECKER_REPO_ID} - AND status='pending' - AND EXTRACT(EPOCH FROM now() - to_timestamp(created)) > 1800;" 2>/dev/null | xargs || echo "?") +# Pending: pending pipelines older than 30min (1800s) +_pending=$(echo "$_pipelines" | jq --argjson now "$_now" ' + [.[] | select(.status == "pending") | select(($now - .created) > 1800)] | length' 2>/dev/null || echo "?") echo "Stuck (>20min): ${_stuck}" echo "Pending (>30min): ${_pending}"