Webmazta commited on
Commit Β·
c20bda5
1
Parent(s): 529bc7e
Add health check, startup logging, and --preload for gunicorn debugging
Browse files- app.py +20 -2
- render.yaml +1 -1
app.py
CHANGED
|
@@ -893,6 +893,15 @@ def api_test_notification():
|
|
| 893 |
return jsonify(results)
|
| 894 |
|
| 895 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 896 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 897 |
# Startup
|
| 898 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -907,14 +916,23 @@ def _start_agent_thread():
|
|
| 907 |
agent_thread = threading.Thread(target=agent_loop, daemon=True)
|
| 908 |
agent_thread.start()
|
| 909 |
|
| 910 |
-
# Initialize database
|
| 911 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
|
| 913 |
# For Gunicorn: start agent thread after worker is ready
|
| 914 |
@app.before_request
|
| 915 |
def _ensure_agent():
|
| 916 |
_start_agent_thread()
|
| 917 |
|
|
|
|
|
|
|
| 918 |
|
| 919 |
if __name__ == "__main__":
|
| 920 |
port = int(os.environ.get("PORT", 5000))
|
|
|
|
| 893 |
return jsonify(results)
|
| 894 |
|
| 895 |
|
| 896 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 897 |
+
# Health Check (no template needed)
|
| 898 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 899 |
+
|
| 900 |
+
@app.route("/health")
|
| 901 |
+
def health_check():
|
| 902 |
+
return jsonify({"status": "ok"}), 200
|
| 903 |
+
|
| 904 |
+
|
| 905 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 906 |
# Startup
|
| 907 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 916 |
agent_thread = threading.Thread(target=agent_loop, daemon=True)
|
| 917 |
agent_thread.start()
|
| 918 |
|
| 919 |
+
# Initialize database with error handling
|
| 920 |
+
print("[STARTUP] Initializing database...")
|
| 921 |
+
try:
|
| 922 |
+
init_db()
|
| 923 |
+
print("[STARTUP] Database initialized successfully")
|
| 924 |
+
except Exception as e:
|
| 925 |
+
print(f"[STARTUP] WARNING: Database init failed: {e}")
|
| 926 |
+
import traceback
|
| 927 |
+
traceback.print_exc()
|
| 928 |
|
| 929 |
# For Gunicorn: start agent thread after worker is ready
|
| 930 |
@app.before_request
|
| 931 |
def _ensure_agent():
|
| 932 |
_start_agent_thread()
|
| 933 |
|
| 934 |
+
print("[STARTUP] App module loaded successfully")
|
| 935 |
+
|
| 936 |
|
| 937 |
if __name__ == "__main__":
|
| 938 |
port = int(os.environ.get("PORT", 5000))
|
render.yaml
CHANGED
|
@@ -3,4 +3,4 @@ services:
|
|
| 3 |
name: content-ai
|
| 4 |
runtime: python
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
-
startCommand: gunicorn app:app --bind 0.0.0.0:$PORT --timeout 120 --workers 1
|
|
|
|
| 3 |
name: content-ai
|
| 4 |
runtime: python
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
+
startCommand: gunicorn app:app --bind 0.0.0.0:$PORT --timeout 120 --workers 1 --preload
|