diff --git a/src/ocrd_network/cli/client.py b/src/ocrd_network/cli/client.py index 39ef62c5f..5dd7fd0f7 100644 --- a/src/ocrd_network/cli/client.py +++ b/src/ocrd_network/cli/client.py @@ -106,6 +106,8 @@ def check_processing_job_status(address: Optional[str], processing_job_id: str): @click.option('--agent-type', default='worker') @click.option('-b', '--block', default=False, is_flag=True, help='If set, the client will block till job timeout, fail or success.') +@click.option('-p', '--print-state', default=False, is_flag=True, + help='If set, the client will print job states by each iteration.') def send_processing_job_request( address: Optional[str], processor_name: str, @@ -146,7 +148,7 @@ def send_processing_job_request( assert processing_job_id print(f"Processing job id: {processing_job_id}") if block: - client.poll_job_status(job_id=processing_job_id) + client.poll_job_status(job_id=processing_job_id, print_state=print_state) @client_cli.group('workflow') @@ -178,6 +180,8 @@ def check_workflow_job_status(address: Optional[str], workflow_job_id: str): @click.option('-w', '--path-to-workflow', required=True) @click.option('-b', '--block', default=False, is_flag=True, help='If set, the client will block till job timeout, fail or success.') +@click.option('-p', '--print-state', default=False, is_flag=True, + help='If set, the client will print job states by each iteration.') def send_workflow_job_request( address: Optional[str], path_to_mets: str, @@ -192,7 +196,7 @@ def send_workflow_job_request( assert workflow_job_id print(f"Workflow job id: {workflow_job_id}") if block: - client.poll_workflow_status(job_id=workflow_job_id) + client.poll_workflow_status(job_id=workflow_job_id, print_state=print_state) @client_cli.group('workspace') diff --git a/src/ocrd_network/client.py b/src/ocrd_network/client.py index c45aa3ecf..5a6831bea 100644 --- a/src/ocrd_network/client.py +++ b/src/ocrd_network/client.py @@ -19,8 +19,7 @@ def __init__( self, server_addr_processing: Optional[str], timeout: int = config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT, - wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP, - print_output: bool = config.OCRD_NETWORK_CLIENT_POLLING_PRINT + wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP ): self.log = getLogger(f"ocrd_network.client") if not server_addr_processing: @@ -30,7 +29,6 @@ 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,15 +46,15 @@ def check_job_status(self, job_id: str): def check_workflow_status(self, workflow_job_id: str): return get_ps_workflow_job_status(self.server_addr_processing, workflow_job_id=workflow_job_id) - def poll_job_status(self, job_id: str) -> str: + def poll_job_status(self, job_id: str, print_state: bool) -> 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, - print_output=self.polling_print_output) + print_state=print_state) - def poll_workflow_status(self, job_id: str) -> str: + def poll_workflow_status(self, job_id: str, print_state: bool) -> 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, - print_output=self.polling_print_output) + print_state=print_state) 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 d3534b4b3..87649d5ad 100644 --- a/src/ocrd_network/client_utils.py +++ b/src/ocrd_network/client_utils.py @@ -4,7 +4,7 @@ def _poll_endpoint_status( - ps_server_host: str, job_id: str, job_type: str, tries: int, wait: int, print_output: bool = False): + ps_server_host: str, job_id: str, job_type: str, tries: int, wait: int, print_state: bool = False): if job_type not in ["workflow", "processor"]: raise ValueError(f"Unknown job type '{job_type}', expected 'workflow' or 'processor'") job_state = JobState.unset @@ -14,7 +14,7 @@ def _poll_endpoint_status( 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: + if print_state: print(f"State of the {job_type} job {job_id}: {job_state}") if job_state == JobState.success or job_state == JobState.failed: break @@ -23,13 +23,13 @@ def _poll_endpoint_status( def poll_job_status_till_timeout_fail_or_success( - ps_server_host: str, job_id: str, tries: int, wait: int, print_output: bool = False) -> JobState: - return _poll_endpoint_status(ps_server_host, job_id, "processor", tries, wait, print_output) + ps_server_host: str, job_id: str, tries: int, wait: int, print_state: bool = False) -> JobState: + return _poll_endpoint_status(ps_server_host, job_id, "processor", tries, wait, print_state) def poll_wf_status_till_timeout_fail_or_success( - ps_server_host: str, job_id: str, tries: int, wait: int, print_output: bool = False) -> JobState: - return _poll_endpoint_status(ps_server_host, job_id, "workflow", tries, wait, print_output) + ps_server_host: str, job_id: str, tries: int, wait: int, print_state: bool = False) -> JobState: + return _poll_endpoint_status(ps_server_host, job_id, "workflow", tries, wait, print_state) def get_ps_deployed_processors(ps_server_host: str): diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index 03d654bc7..d2cc4efce 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -167,11 +167,6 @@ def _ocrd_download_timeout_parser(val): parser=int, default=(True, 3600)) -config.add("OCRD_NETWORK_CLIENT_POLLING_PRINT", - description="Whether the blocking client commands should print status output each iteration.", - 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, ''))