Skip to content

Commit 1f794d2

Browse files
committed
fix(mantis): skip zombie telegram queue runs
1 parent ba7ce3c commit 1f794d2

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

.github/workflows/mantis-telegram-desktop-proof.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,18 @@ jobs:
309309
set -euo pipefail
310310
current_created="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" --jq .created_at)"
311311
stale_before="$(date -u -d '8 hours ago' +%Y-%m-%dT%H:%M:%SZ)"
312+
run_has_active_jobs() {
313+
local run_id="$1"
314+
local run_state="$2"
315+
if [[ "$run_state" != "in_progress" ]]; then
316+
return 0
317+
fi
318+
local active_jobs
319+
active_jobs="$(gh run view "$run_id" --repo "$GITHUB_REPOSITORY" --json jobs --jq '[.jobs[] | select(.status == "queued" or .status == "in_progress" or .status == "waiting" or .status == "pending" or .status == "requested")] | length')"
320+
[[ "$active_jobs" != "0" ]]
321+
}
312322
while true; do
313-
blockers="$(
323+
candidates="$(
314324
for workflow in mantis-telegram-desktop-proof.yml mantis-telegram-live.yml; do
315325
for status in queued in_progress waiting pending requested; do
316326
gh run list --repo "$GITHUB_REPOSITORY" --workflow "$workflow" --status "$status" --limit 100 --json databaseId,status,createdAt,url \
@@ -322,6 +332,12 @@ jobs:
322332
done
323333
done | sort -u
324334
)"
335+
blockers=""
336+
while IFS=$'\t' read -r created run_id run_state url; do
337+
if [[ -n "$run_id" ]] && run_has_active_jobs "${run_id#\#}" "$run_state"; then
338+
blockers+="${created}"$'\t'"${run_id}"$'\t'"${run_state}"$'\t'"${url}"$'\n'
339+
fi
340+
done <<<"$candidates"
325341
if [[ -z "$blockers" ]]; then
326342
break
327343
fi

.github/workflows/mantis-telegram-live.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,18 @@ jobs:
273273
set -euo pipefail
274274
current_created="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" --jq .created_at)"
275275
stale_before="$(date -u -d '8 hours ago' +%Y-%m-%dT%H:%M:%SZ)"
276+
run_has_active_jobs() {
277+
local run_id="$1"
278+
local run_state="$2"
279+
if [[ "$run_state" != "in_progress" ]]; then
280+
return 0
281+
fi
282+
local active_jobs
283+
active_jobs="$(gh run view "$run_id" --repo "$GITHUB_REPOSITORY" --json jobs --jq '[.jobs[] | select(.status == "queued" or .status == "in_progress" or .status == "waiting" or .status == "pending" or .status == "requested")] | length')"
284+
[[ "$active_jobs" != "0" ]]
285+
}
276286
while true; do
277-
blockers="$(
287+
candidates="$(
278288
for workflow in mantis-telegram-desktop-proof.yml mantis-telegram-live.yml; do
279289
for status in queued in_progress waiting pending requested; do
280290
gh run list --repo "$GITHUB_REPOSITORY" --workflow "$workflow" --status "$status" --limit 100 --json databaseId,status,createdAt,url \
@@ -286,6 +296,12 @@ jobs:
286296
done
287297
done | sort -u
288298
)"
299+
blockers=""
300+
while IFS=$'\t' read -r created run_id run_state url; do
301+
if [[ -n "$run_id" ]] && run_has_active_jobs "${run_id#\#}" "$run_state"; then
302+
blockers+="${created}"$'\t'"${run_id}"$'\t'"${run_state}"$'\t'"${url}"$'\n'
303+
fi
304+
done <<<"$candidates"
289305
if [[ -z "$blockers" ]]; then
290306
break
291307
fi

test/scripts/mantis-telegram-desktop-proof-workflow.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ describe("Mantis Telegram Desktop proof workflow", () => {
120120
expect(step.run).toContain("for status in queued in_progress waiting pending requested");
121121
expect(step.run).toContain("stale_before=");
122122
expect(step.run).toContain(".createdAt >= $stale_before");
123-
expect(step.run).not.toContain('select(.status == "queued"');
123+
expect(step.run).toContain("run_has_active_jobs()");
124+
expect(step.run).toContain('gh run view "$run_id"');
125+
expect(step.run).toContain("${run_id#\\#}");
126+
expect(step.run).not.toContain('.[] | select(.status == "queued"');
124127
expect(step.run).toContain("sleep 60");
125128
}
126129
});

0 commit comments

Comments
 (0)