| name: Keep HF backend awake |
|
|
| on: |
| schedule: |
| |
| - cron: '*/5 * * * *' |
| workflow_dispatch: |
|
|
| jobs: |
| ping: |
| runs-on: ubuntu-latest |
| steps: |
| - name: Ping backend health (wake + verify face engine) |
| env: |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} |
| run: | |
| BASE="https://solutionchallenge-solution-challenge-backend.hf.space" |
| ok=0 |
| for i in 1 2 3 4; do |
| if curl -fsS --max-time 180 "$BASE/health/live" | grep -q '"status"'; then |
| echo "Backend live on attempt $i" |
| ok=1 |
| break |
| fi |
| echo "Attempt $i failed, retrying in 20s..." |
| sleep 20 |
| done |
| if [ "$ok" != "1" ]; then |
| echo "::warning::Backend did not respond — checking Space runtime via HF API" |
| pip install -q "huggingface_hub>=0.23.0" |
| python <<'PY' |
| import os, sys |
| from huggingface_hub import HfApi |
| token = os.environ.get("HF_TOKEN", "") |
| if not token: |
| print("HF_TOKEN not set — skip runtime check") |
| sys.exit(0) |
| api = HfApi(token=token) |
| space = "SolutionChallenge/solution_challenge_backend" |
| info = api.space_info(space) |
| rt = info.runtime or {} |
| print(f"Space stage: {getattr(rt, 'stage', rt)} hardware: {getattr(rt, 'hardware', '?')}") |
| try: |
| api.restart_space(space) |
| print("Triggered Space restart") |
| except Exception as exc: |
| print(f"Restart skipped: {exc}") |
| PY |
| exit 0 |
| fi |
| curl -fsS --max-time 60 "$BASE/ai/status" || true |
| |