diff --git a/src/ocrd_network/client.py b/src/ocrd_network/client.py index 012d2ea2e5..1dc92ed991 100644 --- a/src/ocrd_network/client.py +++ b/src/ocrd_network/client.py @@ -9,13 +9,18 @@ class Client: - def __init__(self, server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR_PROCESSING): + def __init__( + self, + server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR_PROCESSING, + timeout: int = config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT, + wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP + ): self.log = getLogger(f"ocrd_network.client") self.server_addr_processing = server_addr_processing verify_server_protocol(self.server_addr_processing) - # TODO: Read these values from the environment config. - self.polling_tries = 900 - self.polling_wait = 30 + self.polling_timeout = timeout + self.polling_wait = wait + self.polling_tries = int(timeout/wait) def poll_job_status_till_timeout_fail_or_success(self, job_id: str) -> str: return poll_job_status_till_timeout_fail_or_success( diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index b3a3e9537d..dc7bee7a33 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -145,6 +145,16 @@ def _ocrd_download_timeout_parser(val): description="Default address of Processing Server to connect to (for `ocrd network client processing`).", default=(True, '')) +config.add("OCRD_NETWORK_CLIENT_POLLING_TIMEOUT", + description="Timeout for a blocking ocrd network client (seconds)", + parser=int, + default=(True, 3600)) + +config.add("OCRD_NETWORK_CLIENT_POLLING_SLEEP", + description="How many seconds to sleep before trying again (seconds)", + parser=int, + default=(True, 30)) + config.add("OCRD_NETWORK_SERVER_ADDR_WORKFLOW", description="Default address of Workflow Server to connect to (for `ocrd network client workflow`).", default=(True, '')) diff --git a/tests/network/config.py b/tests/network/config.py index 67c4ff24b7..9dc38bc0db 100644 --- a/tests/network/config.py +++ b/tests/network/config.py @@ -55,6 +55,20 @@ parser=_ocrd_download_timeout_parser ) +test_config.add( + "OCRD_NETWORK_CLIENT_POLLING_TIMEOUT", + description="Timeout for a blocking ocrd network client", + parser=int, + default=(True, 3600) +) + +test_config.add( + "OCRD_NETWORK_CLIENT_POLLING_SLEEP", + description="How many seconds to sleep before trying again (seconds)", + parser=int, + default=(True, 30) +) + test_config.add( name="OCRD_NETWORK_SERVER_ADDR_PROCESSING", description="Default address of Processing Server to connect to (for `ocrd network client processing`).", diff --git a/tests/network/test_integration_6_client.py b/tests/network/test_integration_6_client.py index fc44705b40..b0ed2bbc3a 100644 --- a/tests/network/test_integration_6_client.py +++ b/tests/network/test_integration_6_client.py @@ -5,12 +5,14 @@ from ocrd_network.client import Client PROCESSING_SERVER_URL = test_config.PROCESSING_SERVER_URL +timeout = test_config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT +wait = test_config.OCRD_NETWORK_CLIENT_POLLING_SLEEP def test_client_processing_processor(): workspace_root = "kant_aufklaerung_1784/data" path_to_mets = assets.path_to(f"{workspace_root}/mets.xml") - client = Client(server_addr_processing=PROCESSING_SERVER_URL) + client = Client(PROCESSING_SERVER_URL, timeout, wait) req_params = { "path_to_mets": path_to_mets, "description": "OCR-D Network client request", @@ -30,7 +32,7 @@ def test_client_processing_workflow(): path_to_mets = assets.path_to(f"{workspace_root}/mets.xml") # TODO: Improve the path resolution path_to_dummy_wf = f"{Path(__file__).parent.resolve()}/dummy-workflow.txt" - client = Client(server_addr_processing=PROCESSING_SERVER_URL) + client = Client(PROCESSING_SERVER_URL, timeout, wait) wf_job_id = client.send_workflow_job_request(path_to_dummy_wf, path_to_mets) print(f"Workflow job id: {wf_job_id}") assert JobState.success == client.poll_wf_status_till_timeout_fail_or_success(wf_job_id)