Skip to content

Keep Supabase Database Active #80

Keep Supabase Database Active

Keep Supabase Database Active #80

# .github/workflows/keep-supabase-alive.yml
name: Keep Supabase Database Active
on:
schedule:
# Run every 5 days at different times to avoid patterns
- cron: "0 14 */5 * *" # Every 5 days at 2 PM UTC
- cron: "30 9 */5 * *" # Every 5 days at 9:30 AM UTC (offset)
workflow_dispatch: # Allow manual triggering
jobs:
ping-database:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Wait for random delay
run: |
# Add random delay to avoid predictable patterns
delay=$((RANDOM % 300 + 60)) # Random delay between 1-5 minutes
echo "Waiting $delay seconds before ping..."
sleep $delay
- name: Ping Health Check Endpoint
run: |
echo "πŸš€ Attempting to ping health endpoint..."
# Try the health endpoint with retry logic
for i in {1..3}; do
response=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 "${{ secrets.APP_URL }}/health/")
if [ $response -eq 200 ]; then
echo "βœ… Health check successful on attempt $i (HTTP $response)"
break
else
echo "⚠️ Health check failed on attempt $i (HTTP $response)"
if [ $i -eq 3 ]; then
echo "❌ All health check attempts failed"
exit 1
fi
sleep 10
fi
done
- name: Alternative Ping (if health endpoint fails)
if: failure()
run: |
echo "πŸ”„ Trying alternative endpoint..."
response=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 "${{ secrets.APP_URL }}/")
echo "Main page response: HTTP $response"
- name: Log Activity
run: |
echo "🎯 Database keep-alive ping completed at $(date)"
echo "πŸ“Š Next scheduled run will be in ~5 days"