Skip to content

Commit

Permalink
add sort to network agents
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Aug 13, 2024
1 parent 8f2861c commit 06a371c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ocrd_network/runtime_data/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, config_path: str) -> None:
# TODO: Reconsider this.
def find_matching_network_agents(
self, worker_only: bool = False, server_only: bool = False, docker_only: bool = False,
native_only: bool = False, str_names_only: bool = False, unique_only: bool = False
native_only: bool = False, str_names_only: bool = False, unique_only: bool = False, sort: bool = False
) -> Union[List[str], List[object]]:
"""Finds and returns a list of matching data objects of type:
`DataProcessingWorker` and `DataProcessorServer`.
Expand All @@ -46,6 +46,7 @@ def find_matching_network_agents(
:py:attr:`native_only` match only native network agents (DataProcessingWorker and DataProcessorServer)
:py:attr:`str_names_only` returns the processor_name filed instead of the Data* object
:py:attr:`unique_only` remove duplicate names from the matches
:py:attr:`sort` sort the result
`worker_only` and `server_only` are mutually exclusive to each other
`docker_only` and `native_only` are mutually exclusive to each other
Expand All @@ -64,6 +65,10 @@ def find_matching_network_agents(
msg = f"Value 'unique_only' is allowed only together with 'str_names_only'"
self.log.exception(msg)
raise ValueError(msg)
if sort and not str_names_only:
msg = f"Value 'sort' is allowed only together with 'str_names_only'"
self.log.exception(msg)
raise ValueError(msg)

# Find all matching objects of type DataProcessingWorker or DataProcessorServer
matched_objects = []
Expand All @@ -88,8 +93,12 @@ def find_matching_network_agents(
matched_names = [match.processor_name for match in matched_objects]
if not unique_only:
return matched_names
# Removes any duplicate entries from matched names
return list(dict.fromkeys(matched_names))
list_matched = list(dict.fromkeys(matched_names))
if not sort:
# Removes any duplicate entries from matched names
return list_matched
list_matched.sort()
return list_matched

def resolve_processor_server_url(self, processor_name) -> str:
processor_server_url = ''
Expand Down

0 comments on commit 06a371c

Please sign in to comment.