Skip to content

Commit 02c2e9c

Browse files
Merge pull request #134 from Geode-solutions/fix/timeout
fix(server timeout): timeout 0 = infinite
2 parents 0ea92a7 + ba02e66 commit 02c2e9c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/opengeodeweb_back/app_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class Config(object):
1212
DEFAULT_PORT = "5000"
1313
CORS_HEADERS = "Content-Type"
1414
UPLOAD_FOLDER = "./uploads"
15-
DESKTOP_APP = False
1615
REQUEST_COUNTER = 0
1716
LAST_REQUEST_TIME = time.time()
1817
LAST_PING_TIME = time.time()

src/opengeodeweb_back/utils_functions.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def teardown_request(current_app):
4343

4444

4545
def kill_task(current_app):
46-
DESKTOP_APP = bool(current_app.config.get("DESKTOP_APP"))
4746
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER"))
4847
LAST_PING_TIME = float(current_app.config.get("LAST_PING_TIME"))
4948
LAST_REQUEST_TIME = float(current_app.config.get("LAST_REQUEST_TIME"))
@@ -52,15 +51,19 @@ def kill_task(current_app):
5251
minutes_since_last_request = (current_time - LAST_REQUEST_TIME) / 60
5352
minutes_since_last_ping = (current_time - LAST_PING_TIME) / 60
5453

55-
if (
56-
(
57-
(minutes_since_last_request > MINUTES_BEFORE_TIMEOUT)
58-
and (DESKTOP_APP == False)
59-
)
60-
or (minutes_since_last_ping > MINUTES_BEFORE_TIMEOUT)
61-
) and (REQUEST_COUNTER == 0):
62-
print("Server timed out due to inactivity, shutting down...", flush=True)
63-
os._exit(0)
54+
if REQUEST_COUNTER > 0:
55+
return
56+
if MINUTES_BEFORE_TIMEOUT == 0:
57+
return
58+
if minutes_since_last_ping > MINUTES_BEFORE_TIMEOUT:
59+
kill_server()
60+
if minutes_since_last_request > MINUTES_BEFORE_TIMEOUT:
61+
kill_server()
62+
63+
64+
def kill_server():
65+
print("Server timed out due to inactivity, shutting down...", flush=True)
66+
os._exit(0)
6467

6568

6669
def versions(list_packages: list):

0 commit comments

Comments
 (0)