diff --git a/src/ocrd_network/client.py b/src/ocrd_network/client.py index 8ec8e541ea..c45aa3ecf3 100644 --- a/src/ocrd_network/client.py +++ b/src/ocrd_network/client.py @@ -19,7 +19,8 @@ def __init__( self, server_addr_processing: Optional[str], timeout: int = config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT, - wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP + wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP, + print_output: bool = config.OCRD_NETWORK_CLIENT_POLLING_PRINT ): self.log = getLogger(f"ocrd_network.client") if not server_addr_processing: @@ -29,6 +30,7 @@ def __init__( self.polling_timeout = timeout self.polling_wait = wait self.polling_tries = int(timeout / wait) + self.polling_print_output = print_output def check_deployed_processors(self): return get_ps_deployed_processors(ps_server_host=self.server_addr_processing) @@ -48,11 +50,13 @@ def check_workflow_status(self, workflow_job_id: str): def poll_job_status(self, job_id: str) -> str: return poll_job_status_till_timeout_fail_or_success( - ps_server_host=self.server_addr_processing, job_id=job_id, tries=self.polling_tries, wait=self.polling_wait) + ps_server_host=self.server_addr_processing, job_id=job_id, tries=self.polling_tries, wait=self.polling_wait, + print_output=self.polling_print_output) def poll_workflow_status(self, job_id: str) -> str: return poll_wf_status_till_timeout_fail_or_success( - ps_server_host=self.server_addr_processing, job_id=job_id, tries=self.polling_tries, wait=self.polling_wait) + ps_server_host=self.server_addr_processing, job_id=job_id, tries=self.polling_tries, wait=self.polling_wait, + print_output=self.polling_print_output) def send_processing_job_request(self, processor_name: str, req_params: dict) -> str: return post_ps_processing_request( diff --git a/src/ocrd_network/client_utils.py b/src/ocrd_network/client_utils.py index 9b924c16a4..3ebe8d3b87 100644 --- a/src/ocrd_network/client_utils.py +++ b/src/ocrd_network/client_utils.py @@ -3,7 +3,7 @@ from .constants import JobState, NETWORK_PROTOCOLS -def _poll_endpoint_status(ps_server_host: str, job_id: str, job_type: str, tries: int, wait: int): +def _poll_endpoint_status(ps_server_host: str, job_id: str, job_type: str, tries: int, wait: int, print_output: bool): if job_type not in ["workflow", "processor"]: raise ValueError(f"Unknown job type '{job_type}', expected 'workflow' or 'processor'") job_state = JobState.unset @@ -13,18 +13,22 @@ def _poll_endpoint_status(ps_server_host: str, job_id: str, job_type: str, tries job_state = get_ps_processing_job_status(ps_server_host, job_id) if job_type == "workflow": job_state = get_ps_workflow_job_status(ps_server_host, job_id) + if print_output: + print(f"State of the {job_type} job {job_id}: {job_state}") if job_state == JobState.success or job_state == JobState.failed: break tries -= 1 return job_state -def poll_job_status_till_timeout_fail_or_success(ps_server_host: str, job_id: str, tries: int, wait: int) -> JobState: - return _poll_endpoint_status(ps_server_host, job_id, "processor", tries, wait) +def poll_job_status_till_timeout_fail_or_success( + ps_server_host: str, job_id: str, tries: int, wait: int, print_output: bool) -> JobState: + return _poll_endpoint_status(ps_server_host, job_id, "processor", tries, wait, print_output) -def poll_wf_status_till_timeout_fail_or_success(ps_server_host: str, job_id: str, tries: int, wait: int) -> JobState: - return _poll_endpoint_status(ps_server_host, job_id, "workflow", tries, wait) +def poll_wf_status_till_timeout_fail_or_success( + ps_server_host: str, job_id: str, tries: int, wait: int, print_output: bool) -> JobState: + return _poll_endpoint_status(ps_server_host, job_id, "workflow", tries, wait, print_output) def get_ps_deployed_processors(ps_server_host: str): diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index 4182456435..ab058c7830 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -160,13 +160,18 @@ def _ocrd_download_timeout_parser(val): config.add("OCRD_NETWORK_CLIENT_POLLING_SLEEP", description="How many seconds to sleep before trying again.", parser=int, - default=(True, 30)) + default=(True, 10)) config.add("OCRD_NETWORK_CLIENT_POLLING_TIMEOUT", description="Timeout for a blocking ocrd network client (in seconds).", parser=int, default=(True, 3600)) +config.add("OCRD_NETWORK_CLIENT_POLLING_PRINT", + description="Timeout for a blocking ocrd network client (in seconds).", + parser=bool, + default=(True, False)) + config.add("OCRD_NETWORK_SERVER_ADDR_WORKFLOW", description="Default address of Workflow Server to connect to (for `ocrd network client workflow`).", default=(True, ''))