Keep SmartReply Backend Alive #1650
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Keep SmartReply Backend Alive | |
| on: | |
| schedule: | |
| # Ping every 55 minutes during active hours (6 AM to 11 PM UTC) | |
| - cron: '*/55 6-23 * * *' | |
| # Ping every 2 hours during off hours (11 PM to 6 AM UTC) | |
| - cron: '*/120 23,0-5 * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| keep-alive: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: 🚀 Ping SmartReply Backend | |
| run: | | |
| echo "🔄 Starting keep-alive ping for SmartReply backend..." | |
| BACKEND_URL="https://smartreply-v1-backend.onrender.com" | |
| echo "📡 Pinging backend health endpoint..." | |
| START_TIME=$(date +%s%3N) | |
| # Try health endpoint first (fastest) | |
| if curl -sf "$BACKEND_URL/api/health" \ | |
| -H "User-Agent: SmartReply-KeepAlive-GitHub/1.0" \ | |
| -H "Accept: application/json" \ | |
| --max-time 30 \ | |
| --retry 2 \ | |
| --retry-delay 5; then | |
| END_TIME=$(date +%s%3N) | |
| RESPONSE_TIME=$((END_TIME - START_TIME)) | |
| echo "✅ Health check successful! Response time: ${RESPONSE_TIME}ms" | |
| else | |
| echo "⚠️ Health endpoint failed, trying generate endpoint..." | |
| # Fallback to generate endpoint with minimal request | |
| if curl -sf "$BACKEND_URL/api/email/generate-reply" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "User-Agent: SmartReply-KeepAlive-GitHub/1.0" \ | |
| -d '{"emailContent":"test","tone":"professional","customPrompt":""}' \ | |
| --max-time 45 \ | |
| --retry 1; then | |
| END_TIME=$(date +%s%3N) | |
| RESPONSE_TIME=$((END_TIME - START_TIME)) | |
| echo "✅ Generate endpoint successful! Response time: ${RESPONSE_TIME}ms" | |
| else | |
| echo "❌ Both endpoints failed. Backend might be down." | |
| exit 1 | |
| fi | |
| fi | |
| echo "🎉 Keep-alive completed successfully!" | |
| - name: 📊 Report Status | |
| if: always() | |
| run: | | |
| if [ $? -eq 0 ]; then | |
| echo "✅ Backend is healthy and responsive" | |
| else | |
| echo "❌ Backend health check failed" | |
| echo "🔧 This will trigger automatic restart on Render" | |
| fi |