Skip to content

Commit 284b98b

Browse files
Apply prepare changes
1 parent 5e18763 commit 284b98b

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

src/opengeodeweb_back/app_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Third party imports
66
# Local application imports
77

8+
89
class Config(object):
910
FLASK_DEBUG = os.environ.get("FLASK_DEBUG", default=False)
1011
DEFAULT_PORT = "5000"

src/opengeodeweb_back/geode_functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .geode_objects import geode_objects_dict
1111
from . import utils_functions
1212

13+
1314
def geode_object_value(geode_object: str):
1415
return geode_objects_dict()[geode_object]
1516

@@ -140,7 +141,9 @@ def list_geode_objects(
140141
key: str = None,
141142
):
142143
return_dict = {}
143-
file_extension = utils_functions.extension_from_filename(os.path.basename(file_absolute_path))
144+
file_extension = utils_functions.extension_from_filename(
145+
os.path.basename(file_absolute_path)
146+
)
144147
geode_objects_filtered_list = filter_geode_objects(key)
145148

146149
for geode_object in geode_objects_filtered_list:

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111

1212
routes = flask.Blueprint("routes", __name__)
1313

14+
1415
@routes.before_request
1516
def before_request():
1617
if "ping" not in flask.request.path:
1718
utils_functions.increment_request_counter(flask.current_app)
1819

20+
1921
@routes.teardown_request
2022
def teardown_request(exception):
2123
if "ping" not in flask.request.path:
2224
utils_functions.decrement_request_counter(flask.current_app)
2325
utils_functions.update_last_request_time(flask.current_app)
2426

27+
2528
schemas = os.path.join(os.path.dirname(__file__), "schemas")
2629

2730
with open(
@@ -274,6 +277,7 @@ def save_viewable_file():
274277
) as file:
275278
ping_json = json.load(file)
276279

280+
277281
@routes.route(
278282
ping_json["route"],
279283
methods=ping_json["methods"],

src/opengeodeweb_back/utils_functions.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212

1313
# Local application imports
1414

15+
1516
def 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+
2123
def 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+
2730
def 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-
5157
def 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-
6469
def 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-
7781
def set_interval(func, sec, args=None):
7882
def func_wrapper():
7983
set_interval(func, sec, args)

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def client():
1414
client.headers = {"Content-type": "application/json", "Accept": "application/json"}
1515
yield client
1616

17+
1718
@pytest.fixture
1819
def app_context():
1920
with app.app_context():

tests/test_geode_functions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,3 @@ def test_geode_objects_output_extensions():
310310
output_extension_value,
311311
) in output_geode_object_value.items():
312312
assert type(output_extension_value["is_saveable"]) is bool
313-
314-

tests/test_utils_functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ def test_increment_request_counter(app_context):
77
utils_functions.increment_request_counter(flask.current_app)
88
assert flask.current_app.config.get("REQUEST_COUNTER") == 1
99

10+
1011
def test_decrement_request_counter(app_context):
1112
assert flask.current_app.config.get("REQUEST_COUNTER") == 1
1213
utils_functions.decrement_request_counter(flask.current_app)
1314
assert flask.current_app.config.get("REQUEST_COUNTER") == 0
1415

16+
1517
def test_update_last_request_time(app_context):
1618
LAST_REQUEST_TIME = flask.current_app.config.get("LAST_REQUEST_TIME")
1719
utils_functions.update_last_request_time(flask.current_app)
@@ -45,4 +47,4 @@ def test_handle_exception(client):
4547
assert type(data) is dict
4648
assert type(data["description"]) is str
4749
assert type(data["name"]) is str
48-
assert type(data["code"]) is int
50+
assert type(data["code"]) is int

0 commit comments

Comments
 (0)