Spaces:
Running
Running
Upload folder using huggingface_hub
Browse filesFiles changed (2)
1234567891011121314151617181920212223242526name: Keep-Alive Ping
on: schedule: # Run at 12:00 PM (UTC) every day - cron: '0 12 * * *' workflow_dispatch: # Allow manual triggers from GitHub Actions UI
jobs: ping: runs-on: ubuntu-latest steps: - name: Hit the Keep-Alive endpoint run: | # Send a GET request to the HF Space keep-alive endpoint # Replace the URL below with the actual Hugging Face Space URL if different RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" https://customercore.hf.space/api/v1/keep-alive) echo "Endpoint responded with HTTP code: $RESPONSE" if [ "$RESPONSE" -eq 200 ]; then echo "Keep-alive ping successful!" exit 0 else echo "Failed to ping the keep-alive endpoint. HTTP code: $RESPONSE" exit 1 fi202 unmodified lines203204205202 unmodified lines"db_url_redacted": redacted_db_url})202 unmodified lines203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247202 unmodified lines"db_url_redacted": redacted_db_url})@router.get("/keep-alive", summary="Keep-alive ping for Supabase and HF Spaces")async def keep_alive() -> JSONResponse:"""Lightweight endpoint to keep the database awake on the free tier.This executes a fast query on Supabase."""import osimport httpxsupabase_url = os.getenv("SUPABASE_URL")supabase_key = os.getenv("SUPABASE_KEY")if not supabase_url or not supabase_key:return JSONResponse(status_code=500,content={"status": "error", "message": "Supabase credentials not configured."})try:headers = {"apikey": supabase_key,"Authorization": f"Bearer {supabase_key}"}# Requesting a limit=1 from tickets table is very fast and counts as activityresp = httpx.get(f"{supabase_url}/rest/v1/tickets?select=id&limit=1", headers=headers, timeout=5.0)if resp.status_code >= 400:return JSONResponse(status_code=500,content={"status": "error", "message": f"Supabase responded with {resp.status_code}"})return JSONResponse(status_code=200,content={"status": "success", "message": "Keep-alive ping successful"})except Exception as exc:return JSONResponse(status_code=500,content={"status": "error", "message": str(exc)})
.github/workflows/keepalive.ymlAdded+26
src/api/routers/health.py+42