Skip to content
Latchkey

How to Run a Long Job With a Heartbeat in GitHub Actions

A long, quiet step looks hung and risks the no-output timeout; a heartbeat proves it is alive.

Start a background loop that prints a timestamp every minute, run the long task, then stop the heartbeat in a cleanup.

Steps

  • Start a background loop that echoes progress on an interval.
  • Capture its PID so you can stop it later.
  • Run the long-running task in the foreground.
  • Kill the heartbeat in an always() cleanup step.

Workflow

.github/workflows/long.yml
jobs:
  long:
    runs-on: ubuntu-latest
    timeout-minutes: 120
    steps:
      - uses: actions/checkout@v4
      - name: Run with heartbeat
        run: |
          ( while true; do echo "heartbeat $(date -u +%T)"; sleep 60; done ) &
          HB=$!
          ./long-task.sh
          kill $HB

Gotchas

  • Set a generous timeout-minutes so the job is not cut off mid-task.
  • Use set -o pipefail so a failing long task is not masked by the heartbeat.
  • Latchkey runs long jobs on cheaper runners that self-heal, so a transient infra blip does not waste hours of work.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →