Print runner wait time in all workflow jobs #504

Closed
opened 2026-06-06 19:09:46 +00:00 by guettlibot · 1 comment
guettlibot commented 2026-06-06 19:09:46 +00:00 (Migrated from codeberg.org)

Goal

Add visibility into how long each CI job waits for a runner to pick it up (queue time). Currently this is invisible — a job that appears to hang might just be waiting for a runner.

Approach

Add a Print runner wait time step as the first step in every job. It records the current time (= runner pickup time) and fetches the run's created_at from the Forgejo API (= queued time). The difference is the wait duration.

The step uses github.token (available in all jobs), so no new secrets are needed.

Step to add

- name: Print runner wait time
  env:
    FORGEJO_TOKEN: ${{ github.token }}
    RUN_NUMBER: ${{ github.run_number }}
  run: |
    runner_start=$(date +%s)
    created_at=$(curl -sf       -H "Authorization: token $FORGEJO_TOKEN"       "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100"       | python3 -c "
import sys, json
data = json.load(sys.stdin)
for r in data.get('workflow_runs', []):
    if r.get('run_number') == $RUN_NUMBER:
        print(r['created_at'])
        break
" 2>/dev/null)
    if [ -n "$created_at" ]; then
      queued_epoch=$(date -d "$created_at" +%s)
      wait_seconds=$((runner_start - queued_epoch))
      echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
    else
      echo "Runner wait time: unknown (API lookup failed)"
    fi

Jobs to update

.forgejo/workflows/ci.yml

  • check (Full Project Check)

.forgejo/workflows/deploy.yml

  • check-changes (Detect Changed Files)
  • deploy-playstore (Build & Deploy to Play Store)
  • deploy-apk (Build & Deploy APK to Server)
  • build-linux (Build Linux Release)
  • label-deploy-health (Update Deploy Health Label)

.forgejo/workflows/website.yml

  • the single deploy job

.forgejo/workflows/firebase-tests.yml

  • check-changes (Detect Firebase-Relevant Changes)
  • test-android-firebase (Android Instrumented Tests)

Notes

  • Place this step before actions/checkout so the timer starts as close to runner pickup as possible.
  • The Forgejo tasks API (/api/v1/repos/.../actions/tasks) returns created_at = when the run was triggered/queued. run_started_at is the same value and cannot be used for this purpose.
  • limit=100 covers recent runs — if the run is not found the step prints unknown and continues without failing.
## Goal Add visibility into how long each CI job waits for a runner to pick it up (queue time). Currently this is invisible — a job that appears to hang might just be waiting for a runner. ## Approach Add a `Print runner wait time` step as the **first step** in every job. It records the current time (= runner pickup time) and fetches the run's `created_at` from the Forgejo API (= queued time). The difference is the wait duration. The step uses `github.token` (available in all jobs), so no new secrets are needed. ## Step to add ```yaml - name: Print runner wait time env: FORGEJO_TOKEN: ${{ github.token }} RUN_NUMBER: ${{ github.run_number }} run: | runner_start=$(date +%s) created_at=$(curl -sf -H "Authorization: token $FORGEJO_TOKEN" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" | python3 -c " import sys, json data = json.load(sys.stdin) for r in data.get('workflow_runs', []): if r.get('run_number') == $RUN_NUMBER: print(r['created_at']) break " 2>/dev/null) if [ -n "$created_at" ]; then queued_epoch=$(date -d "$created_at" +%s) wait_seconds=$((runner_start - queued_epoch)) echo "Runner wait time: ${wait_seconds}s (queued at $created_at)" else echo "Runner wait time: unknown (API lookup failed)" fi ``` ## Jobs to update ### `.forgejo/workflows/ci.yml` - `check` (Full Project Check) ### `.forgejo/workflows/deploy.yml` - `check-changes` (Detect Changed Files) - `deploy-playstore` (Build & Deploy to Play Store) - `deploy-apk` (Build & Deploy APK to Server) - `build-linux` (Build Linux Release) - `label-deploy-health` (Update Deploy Health Label) ### `.forgejo/workflows/website.yml` - the single deploy job ### `.forgejo/workflows/firebase-tests.yml` - `check-changes` (Detect Firebase-Relevant Changes) - `test-android-firebase` (Android Instrumented Tests) ## Notes - Place this step **before** `actions/checkout` so the timer starts as close to runner pickup as possible. - The Forgejo tasks API (`/api/v1/repos/.../actions/tasks`) returns `created_at` = when the run was triggered/queued. `run_started_at` is the same value and cannot be used for this purpose. - `limit=100` covers recent runs — if the run is not found the step prints `unknown` and continues without failing.
guettlibot commented 2026-06-07 00:42:17 +00:00 (Migrated from codeberg.org)

The PR was created and squash-merged successfully. Here's what was done:


PR: https://codeberg.org/guettli/sharedinbox/pulls/517 (Closes #504)

What changed: Added a Print runner wait time step as the first step in every job across all four workflow files:

  • .forgejo/workflows/ci.ymlcheck job
  • .forgejo/workflows/deploy.ymlcheck-changes, deploy-playstore, deploy-apk, build-linux, label-deploy-health jobs
  • .forgejo/workflows/website.ymldeploy job
  • .forgejo/workflows/firebase-tests.ymlcheck-changes, test-android-firebase jobs

The step records the runner pickup time via date +%s, then fetches the run's created_at from the Forgejo tasks API using github.token (no new secrets needed). If the API lookup fails it prints unknown and continues without blocking the job. The step is placed before actions/checkout so the timer starts as early as possible.

The PR was created and squash-merged successfully. Here's what was done: --- **PR:** https://codeberg.org/guettli/sharedinbox/pulls/517 (Closes #504) **What changed:** Added a `Print runner wait time` step as the first step in every job across all four workflow files: - `.forgejo/workflows/ci.yml` — `check` job - `.forgejo/workflows/deploy.yml` — `check-changes`, `deploy-playstore`, `deploy-apk`, `build-linux`, `label-deploy-health` jobs - `.forgejo/workflows/website.yml` — `deploy` job - `.forgejo/workflows/firebase-tests.yml` — `check-changes`, `test-android-firebase` jobs The step records the runner pickup time via `date +%s`, then fetches the run's `created_at` from the Forgejo tasks API using `github.token` (no new secrets needed). If the API lookup fails it prints `unknown` and continues without blocking the job. The step is placed before `actions/checkout` so the timer starts as early as possible.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: guettli/sharedinbox#504