File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import json
3
+ from http .server import BaseHTTPRequestHandler , HTTPServer
4
+
5
+ class HealthCheckHandler (BaseHTTPRequestHandler ):
6
+ def do_GET (self ):
7
+ if self .path == "/" :
8
+ # Send a 200 OK response
9
+ self .send_response (200 )
10
+ self .send_header ("Content-Type" , "application/json" )
11
+ self .end_headers ()
12
+
13
+ # Write JSON response
14
+ response = json .dumps ({"status" : "running" })
15
+ self .wfile .write (response .encode ())
16
+ else :
17
+ # Send a 404 Not Found response for other paths
18
+ self .send_response (404 )
19
+ self .end_headers ()
20
+
21
+ def run_health_check_server ():
22
+ health_port = int (os .getenv ("HEALTHCHECK_PORT" , 9000 ))
23
+ server_address = ('' , health_port )
24
+ httpd = HTTPServer (server_address , HealthCheckHandler )
25
+ print (f"Health check server running on port { health_port } " )
26
+ httpd .serve_forever ()
Original file line number Diff line number Diff line change
1
+ import os
2
+ from threading import Thread
1
3
from dracan .core .app_factory import create_app
4
+ from dracan .core .health_check import run_health_check_server
2
5
3
6
app = create_app ()
4
7
5
8
if __name__ == '__main__' :
9
+ # Check if health check should be disabled
10
+ healthcheck_disabled = os .getenv ("HEALTHCHECK_DISABLED" , "false" ).lower () == "true"
11
+
12
+ if not healthcheck_disabled :
13
+ # Start the health check server in a separate thread
14
+ health_thread = Thread (target = run_health_check_server )
15
+ health_thread .daemon = True # Ensures the thread stops when the main process exits
16
+ health_thread .start ()
17
+ else :
18
+ print ("Healthcheck not running, disabled by env variable." )
19
+
6
20
# Run the Flask app
7
- app .run (host = '0.0.0.0' , port = 5000 )
21
+ app .run (host = '0.0.0.0' , port = 5000 )
You can’t perform that action at this time.
0 commit comments