From 74da8889a0159b3e58004634b65fcf39fcc437b3 Mon Sep 17 00:00:00 2001 From: Francesco Nazzaro Date: Wed, 2 Oct 2024 17:26:01 +0200 Subject: [PATCH] fix processing time priority algorithm (#135) * add started_at != None on query * qa --- cads_broker/database.py | 1 + tests/test_02_database.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cads_broker/database.py b/cads_broker/database.py index f135d72a..383c2902 100644 --- a/cads_broker/database.py +++ b/cads_broker/database.py @@ -452,6 +452,7 @@ def get_users_queue_from_processing_time( SystemRequest.finished_at >= interval_start, SystemRequest.finished_at < interval_stop, SystemRequest.status != "deleted", + SystemRequest.started_at.is_not(None), ) where_clause = sa.sql.or_(interval_clause, SystemRequest.status == "running") diff --git a/tests/test_02_database.py b/tests/test_02_database.py index bc63afff..f7f858ef 100644 --- a/tests/test_02_database.py +++ b/tests/test_02_database.py @@ -608,7 +608,7 @@ def test_get_request(session_obj: sa.orm.sessionmaker) -> None: assert request.request_uid == request_uid -def test_get_users_queue_per_cost(session_obj: sa.orm.sessionmaker) -> None: +def test_get_users_queue_from_processing_time(session_obj: sa.orm.sessionmaker) -> None: adaptor_properties = mock_config() request_1 = mock_system_request( status="successful", @@ -647,6 +647,13 @@ def test_get_users_queue_per_cost(session_obj: sa.orm.sessionmaker) -> None: adaptor_properties_hash=adaptor_properties.hash, user_uid="user3", ) + request_7 = mock_system_request( + status="failed", + adaptor_properties_hash=adaptor_properties.hash, + user_uid="user3", + started_at=None, + finished_at=datetime.datetime.now() - datetime.timedelta(hours=10), + ) with session_obj() as session: session.add(adaptor_properties) session.add(request_1) @@ -655,6 +662,7 @@ def test_get_users_queue_per_cost(session_obj: sa.orm.sessionmaker) -> None: session.add(request_4) session.add(request_5) session.add(request_6) + session.add(request_7) session.commit() with session_obj() as session: users_cost = db.get_users_queue_from_processing_time(