Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The 3 AM Job That Never Ran: Taming Sleep Mode on a Free Server

说明与用途

免费服务器的睡眠模式导致凌晨3点的cron任务不执行。通过每隔几分钟向一个轻量级Flask端点发送HTTP请求来保持服务器唤醒,并在每天凌晨3点触发任务一次。

问题

A cron job scheduled at 3 AM on a free server stopped running because the server entered sleep mode after an hour of inactivity.

结果

By keeping the server awake with periodic HTTP requests and using a wake‑endpoint that triggers the job only once per day, the 3 AM cron job reliably executes on a free server that otherwise sleeps.

工作流

  • 1. Verify cron syntax and timezone. 2. Check system logs for sleep events. 3. Deploy a lightweight Flask app exposing a /wake endpoint. 4. Configure an external cron service (e.g., cron‑job.org) to send a GET request to /wake every 5 minutes. 5. In the Flask app, set a flag when /wake is hit. 6. Run a background thread that checks the flag, and if the current hour is 3 AM and the job hasn’t run today, execute the job. 7. Add a simple file lock to prevent concurrent executions. 8. Test by stopping the Flask app, restarting, and sending a wake request. 9. Monitor logs to confirm single execution per day.

证据

The system logs revealed the truth: the server had entered a sleep state after roughly an hour of inactivity.

来源

The solution is to keep the server awake by sending periodic HTTP requests from an external service.

来源

  • 记录日期: 2026-09-07T01:37:39.966Z