1212
1313# Local application imports
1414
15+
1516def increment_request_counter (current_app ):
1617 if "REQUEST_COUNTER" in current_app .config :
1718 REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
1819 REQUEST_COUNTER += 1
1920 current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
2021
22+
2123def decrement_request_counter (current_app ):
2224 if "REQUEST_COUNTER" in current_app .config :
2325 REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
2426 REQUEST_COUNTER -= 1
2527 current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
2628
29+
2730def update_last_request_time (current_app ):
2831 if "LAST_REQUEST_TIME" in current_app .config :
2932 LAST_REQUEST_TIME = time .time ()
@@ -40,14 +43,17 @@ def kill_task(current_app):
4043 minutes_since_last_request = (current_time - LAST_REQUEST_TIME ) / 60
4144 minutes_since_last_ping = (current_time - LAST_PING_TIME ) / 60
4245
43- if (((minutes_since_last_request > MINUTES_BEFORE_TIMEOUT ) and (DESKTOP_APP == False )) or
44- (minutes_since_last_ping > MINUTES_BEFORE_TIMEOUT )
45- ) and (REQUEST_COUNTER == 0 ):
46+ if (
47+ (
48+ (minutes_since_last_request > MINUTES_BEFORE_TIMEOUT )
49+ and (DESKTOP_APP == False )
50+ )
51+ or (minutes_since_last_ping > MINUTES_BEFORE_TIMEOUT )
52+ ) and (REQUEST_COUNTER == 0 ):
4653 print ("Server timed out due to inactivity, shutting down..." , flush = True )
4754 os ._exit (0 )
4855
4956
50-
5157def versions (list_packages : list ):
5258 list_with_versions = []
5359 for package in list_packages :
@@ -60,7 +66,6 @@ def versions(list_packages: list):
6066 return list_with_versions
6167
6268
63-
6469def validate_request (request , schema ):
6570 json_data = request .get_json (force = True , silent = True )
6671
@@ -73,7 +78,6 @@ def validate_request(request, schema):
7378 flask .abort (400 , f"Validation error: { e .message } " )
7479
7580
76-
7781def set_interval (func , sec , args = None ):
7882 def func_wrapper ():
7983 set_interval (func , sec , args )
0 commit comments