Skip to content

Commit 3b30d89

Browse files
committed
fix(Utils): add health route
1 parent cc5e2b5 commit 3b30d89

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/opengeodeweb_back/app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ def create_app(name: str) -> flask.Flask:
2323
)
2424
if FLASK_DEBUG == False:
2525
app.config.from_object(app_config.ProdConfig)
26-
SECONDS_BETWEEN_SHUTDOWNS: float = float(
27-
app.config.get("SECONDS_BETWEEN_SHUTDOWNS") or 60.0
28-
)
29-
utils_functions.set_interval(
30-
utils_functions.kill_task, SECONDS_BETWEEN_SHUTDOWNS, app
31-
)
3226
else:
3327
app.config.from_object(app_config.DevConfig)
3428

@@ -64,6 +58,13 @@ def return_error() -> Response:
6458
flask.abort(500, f"Test")
6559
return flask.make_response({}, 500)
6660

61+
@app.route(
62+
"/health",
63+
methods=["GET"],
64+
)
65+
def health() -> Response:
66+
return flask.make_response(utils_functions.kill_task(flask.current_app), 200)
67+
6768
@app.route("/", methods=["POST"])
6869
@cross_origin()
6970
def root() -> Response:

src/opengeodeweb_back/utils_functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def teardown_request(
7878
print(message, flush=True)
7979

8080

81-
def kill_task(current_app: flask.Flask) -> None:
81+
def kill_task(current_app: flask.Flask) -> bool:
8282
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER", 0))
8383
LAST_PING_TIME = float(current_app.config.get("LAST_PING_TIME", 0))
8484
LAST_REQUEST_TIME = float(current_app.config.get("LAST_REQUEST_TIME", 0))
@@ -88,13 +88,14 @@ def kill_task(current_app: flask.Flask) -> None:
8888
minutes_since_last_ping = (current_time - LAST_PING_TIME) / 60
8989

9090
if REQUEST_COUNTER > 0:
91-
return
91+
return False
9292
if MINUTES_BEFORE_TIMEOUT == 0:
93-
return
93+
return False
9494
if minutes_since_last_ping > MINUTES_BEFORE_TIMEOUT:
95-
kill_server()
95+
return True
9696
if minutes_since_last_request > MINUTES_BEFORE_TIMEOUT:
97-
kill_server()
97+
return True
98+
return False
9899

99100

100101
def kill_server() -> None:

0 commit comments

Comments
 (0)