Skip to content

Latest commit

 

History

History
202 lines (153 loc) · 4.71 KB

File metadata and controls

202 lines (153 loc) · 4.71 KB

Keep-Alive System for Render Free Tier

🎯 Problem

Render's free tier puts services to sleep after 15 minutes of inactivity.

✅ Solutions Implemented

1. GitHub Actions (Primary - FREE)

File: .github/workflows/keep-alive.yml

How it works:

  • Runs automatically every 5 minutes
  • Pings your bot at: https://api-bot-in6q.onrender.com/health
  • Keeps the service active 24/7
  • Zero cost, zero maintenance

Status: ✅ Active after push

2. Internal Self-Ping (Backup)

File: bot.py lines 139-158

How it works:

  • Bot pings itself every 5 minutes
  • Uses localhost:10000/
  • Only works when bot is already running
  • Helps maintain activity

Status: ✅ Already implemented


📊 Keep-Alive Workflow

Every 5 minutes:
  GitHub Actions (external)
      ↓
  Pings /health endpoint
      ↓
  Render wakes up (if sleeping)
      ↓
  Bot responds with 200 OK
      ↓
  Internal self-ping activates
      ↓
  Bot stays awake

🔍 How to Monitor

Check GitHub Actions:

  1. Go to: https://github.com/Masterofowls/API_Bot/actions
  2. See workflow runs every 5 minutes
  3. Green checkmark = working ✅
  4. Red X = needs attention ⚠️

Check Render Logs:

GET /health 200 OK
✓ Keep-alive ping sent

Check Bot Status:

  • Telegram bot should respond instantly (not delayed)
  • No "waking up" messages in logs

🛠️ Setup Instructions

Step 1: Push to GitHub

git add .github/workflows/keep-alive.yml KEEP_ALIVE.md
git commit -m "Add GitHub Actions keep-alive system"
git push

Step 2: Enable GitHub Actions

  1. Go to: https://github.com/Masterofowls/API_Bot/actions
  2. If disabled, click "I understand my workflows, go ahead and enable them"
  3. Workflow will start running automatically

Step 3: Manual Test (Optional)

  1. Go to Actions tab
  2. Click "Keep Bot Alive on Render"
  3. Click "Run workflow" → "Run workflow"
  4. Wait 30 seconds, check for green checkmark

🌐 Alternative Solutions (If Needed)

UptimeRobot (FREE)

If GitHub Actions fails:

  1. Go to: https://uptimerobot.com/
  2. Sign up (free)
  3. Add monitor:
    • Type: HTTP(s)
    • URL: https://api-bot-in6q.onrender.com/health
    • Interval: 5 minutes
  4. Save

Cron-job.org (FREE)

Another backup option:

  1. Go to: https://cron-job.org/
  2. Sign up
  3. Create job:
    • URL: https://api-bot-in6q.onrender.com/health
    • Schedule: */5 * * * * (every 5 min)
  4. Enable

📈 Expected Results

Before Keep-Alive:

  • Bot sleeps after 15 minutes
  • First message after sleep: 10-30 second delay
  • Render shows: "Service waking up..."

After Keep-Alive:

  • Bot always responsive (< 1 second)
  • No wake-up delays
  • Render logs show regular activity
  • 24/7 uptime

⚠️ Important Notes

  1. GitHub Actions is FREE for public repos (unlimited minutes)
  2. Render free tier has 750 hours/month (keep-alive uses ~720 hours)
  3. If repo is private, you have 2,000 minutes/month (enough for ~27 days)
  4. Multiple pings (GitHub + internal) ensure reliability

🐛 Troubleshooting

Workflow not running?

Check: Is repo public? Private repos have minute limits. Fix: Go to repo Settings → Actions → General → Enable workflows

Still going to sleep?

Check: GitHub Actions logs for errors Fix: Add UptimeRobot as backup (see above)

Bot not responding to pings?

Check: Render logs at https://dashboard.render.com/ Fix: Manual deploy to restart service


📝 Technical Details

Cron Schedule Explained:

*/5 * * * *
 │  │ │ │ │
 │  │ │ │ └─── Day of week (0-7, 0=Sunday)
 │  │ │ └───── Month (1-12)
 │  │ └─────── Day of month (1-31)
 │  └───────── Hour (0-23)
 └─────────── Minute (0-59) - */5 means every 5 minutes

Health Endpoint:

  • URL: /health
  • Response: {"status": "ok", "uptime": seconds}
  • HTTP 200 OK
  • Fast response (< 100ms)

✅ Verification Checklist

After setup:

  • .github/workflows/keep-alive.yml file pushed
  • GitHub Actions enabled in repo settings
  • First workflow run completed (check Actions tab)
  • Bot responding instantly in Telegram
  • Render logs show no sleep messages
  • Test by not using bot for 20 minutes
  • Bot still responds instantly after 20 min

🎉 Success Indicators

You'll know it's working when:

  1. GitHub Actions shows green checkmarks every 5 minutes
  2. Render dashboard shows consistent activity
  3. Bot responds instantly at any time of day
  4. No "waking up" delays in Telegram
  5. Render free hours slowly counting up (not resetting)

Status: ✅ Ready to deploy Next: Push to GitHub and enable Actions