Skip to content

Keep backend warm #3479

Keep backend warm

Keep backend warm #3479

Workflow file for this run

name: Keep backend warm
on:
schedule:
# every hour at minute 0 (UTC)
- cron: '0 * * * *'
workflow_dispatch: {}
jobs:
keepalive:
runs-on: ubuntu-latest
steps:
- name: Curl backend or keepalive endpoint
env:
KEEPALIVE_URL: ${{ secrets.KEEPALIVE_URL }}
KEEPALIVE_URL2: ${{ secrets.KEEPALIVE_URL2 }}
KEEPALIVE_AUTH: ${{ secrets.KEEPALIVE_AUTH }}
run: |
if [ -z "$KEEPALIVE_URL" ]; then
echo "KEEPALIVE_URL is not set. Skipping keepalive (no secret configured in this repository)."
exit 0
fi
echo "Pinging $KEEPALIVE_URL"
# Use header-based auth if KEEPALIVE_AUTH is set (optional)
if [ -n "$KEEPALIVE_AUTH" ]; then
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "x-keepalive-secret: $KEEPALIVE_AUTH" "$KEEPALIVE_URL")
STATUS_2=$(curl -s -o /dev/null -w "%{http_code}" -H "x-keepalive-secret: $KEEPALIVE_AUTH" "$KEEPALIVE_URL2")
else
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$KEEPALIVE_URL")
STATUS_2=$(curl -s -o /dev/null -w "%{http_code}" "$KEEPALIVE_URL2")
fi
echo "status=$STATUS"
echo "status_2=$STATUS_2"
# Check if either request failed and set a failure flag
FAIL=0
if [ "$STATUS" -ge 400 ]; then
echo "Keepalive request for KEEPALIVE_URL returned $STATUS" >&2
FAIL=1
fi
if [ "$STATUS_2" -ge 400 ]; then
echo "Keepalive request for KEEPALIVE_URL2 returned $STATUS_2" >&2
FAIL=1
fi
# Exit with an error if the flag was set
if [ "$FAIL" -eq 1 ]; then
exit 1
fi