Skip to content
Latchkey

How to Shut Down Idle CI Resources

A hung job that runs to the six-hour ceiling wastes more energy than any test it was meant to run.

Idle CI resources leak cost quietly: a stuck job burning its full timeout, a preview environment nobody closed, a database left running. Bounding runtime and tearing down environments on close removes that drain.

Steps

  • Set timeout-minutes on every job so a hang is killed, not run to the 360-minute default.
  • Tear down preview environments when a pull request closes.
  • Let service containers stop with the job rather than leaving external ones running.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - run: npm ci && npm test
  cleanup-preview:
    if: github.event.action == 'closed'
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/destroy-preview.sh "${{ github.event.number }}"

Tradeoffs

  • Set the timeout slightly above normal duration so healthy runs are not cut off.
  • A timed-out job is marked failed and can fail dependents through needs.

Related guides

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