Skip to content

Keep the API warm

Keep the API warm #938

Workflow file for this run

# Render's free instance sleeps after ~15 minutes idle, and waking it costs ~50s of
# container boot. This asks for a ping every 10 minutes to stay under that threshold.
#
# READ THIS BEFORE TRUSTING IT: the schedule below does not work, and the failure is
# silent -- every run goes green, because a run that never fires cannot go red.
# Measured over one 15-hour window: 89 runs due, 8 delivered (~9%), gaps up to 3.5
# hours. GitHub throttles high-frequency cron on shared runners and the requested
# interval is a hint, not a contract. Tightening it to */5 makes the throttling worse,
# not better. Against a 15-minute sleep window, ~2-hour delivery keeps nothing warm.
#
# It stays enabled because a ping that does land is free and harmless. But the ways to
# actually get a warm instance are:
# 1. workflow_dispatch below -- manual runs are NOT throttled. Warm in ~75s. Use this
# before a demo. (Or just open the site yourself two minutes early; same effect.)
# 2. An external pinger (cron-job.org / UptimeRobot / Better Stack, all free) hitting
# /health every 5 minutes. That one genuinely works, and it needs an account rather
# than a commit, which is why it is not in this repo.
#
# The real safety net is in the UI, not here: the axios timeout is 180s and the
# dashboard shows a "waking the server" note after 6s, so a cold visitor waits through
# a wait instead of staring at what looks like a hang.
name: Keep the API warm
on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch: # so it can be kicked by hand right before a demo
jobs:
ping:
runs-on: ubuntu-latest
steps:
- name: Ping /health
run: |
URL="${{ vars.API_URL || 'https://xai-aml-final.onrender.com' }}/health"
# A sleeping instance can take ~60s to answer, which is not a failure --
# it is exactly the case this workflow exists to prevent. Allow for it.
code=$(curl -sS -o /tmp/body -w '%{http_code}' --max-time 120 "$URL") || {
echo "::warning::Could not reach $URL (curl failed). The instance may be down."
exit 0
}
echo "$URL -> $code"
cat /tmp/body; echo
if [ "$code" != "200" ]; then
echo "::warning::$URL returned $code, expected 200."
fi
# Never fail the build. A red X every time Render hiccups would train us
# to ignore this workflow, and it is not gating anything.