From dfb7e0ebd1bcd0810aba080d0f7517b6d97a1740 Mon Sep 17 00:00:00 2001 From: Reynov Christian Date: Fri, 15 Aug 2025 16:28:54 +0800 Subject: [PATCH] Update README and add health check endpoint Update README to reflect the correct script name for running the application. Add a health check endpoint to the Flask app to verify server status. --- README.md | 3 ++- run.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d21bead..cf32fe3 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,8 @@ DB_NAME=bots.db ``` 5. **Run the application:** ```bash - python app.py + + python run.py ``` > **Important:** You must have the MetaTrader 5 terminal installed and running on the same machine. diff --git a/run.py b/run.py index 555d442..5c33acf 100644 --- a/run.py +++ b/run.py @@ -4,6 +4,7 @@ import os import atexit import logging import MetaTrader5 as mt5 +from flask import jsonify from core import create_app from core.utils.mt5 import initialize_mt5 from core.bots.controller import shutdown_all_bots, ambil_semua_bot @@ -21,6 +22,11 @@ def shutdown_app(): # Panggil pabrik untuk membuat aplikasi kita app = create_app() +@app.route('/api/health') +def health_check(): + """Endpoint untuk memastikan server berjalan.""" + return jsonify({"status": "ok", "message": "Server is running"}) + if __name__ == '__main__': # --- Inisialisasi MT5 Terpusat --- # Dilakukan di sini untuk memastikan hanya berjalan sekali. @@ -33,11 +39,14 @@ if __name__ == '__main__': ambil_semua_bot() # Muat bot setelah koneksi berhasil atexit.register(shutdown_app) # Daftarkan shutdown HANYA jika koneksi berhasil except Exception as e: - logging.critical(f"GAGAL total saat inisialisasi MT5 di run.py: {e}", exc_info=True) + logging.critical( + f"GAGAL total saat inisialisasi MT5 di run.py: {e}", + exc_info=True + ) app.run( debug=os.getenv('FLASK_DEBUG', 'False').lower() == 'true', host=os.getenv('FLASK_HOST', '127.0.0.1'), port=int(os.getenv('FLASK_PORT', 5000)), - use_reloader=False # Ini tetap sangat penting + use_reloader=False ) \ No newline at end of file