Skip to content

Commit

Permalink
fix processing time priority algorithm (#135)
Browse files Browse the repository at this point in the history
* add started_at != None on query

* qa
  • Loading branch information
francesconazzaro authored Oct 2, 2024
1 parent a086d50 commit 74da888
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions cads_broker/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
10 changes: 9 additions & 1 deletion tests/test_02_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 74da888

Please sign in to comment.