diff --git a/src/ocrd_network/cli/client.py b/src/ocrd_network/cli/client.py index c2b6c500d1..a5f8b0e085 100644 --- a/src/ocrd_network/cli/client.py +++ b/src/ocrd_network/cli/client.py @@ -79,7 +79,7 @@ def send_processing_job_request( assert processing_job_id print(f"Processing job id: {processing_job_id}") if block_till_job_end: - client.poll_job_status_till_timeout_fail_or_success(processing_job_id) + client.poll_job_status_till_timeout_fail_or_success(job_id=processing_job_id) @client_cli.group('workflow') @@ -90,6 +90,25 @@ def workflow_cli(): pass +@processing_cli.command('run') +@click.option('--address') +@click.option('-m', '--path-to-mets', required=True) +@click.option('-w', '--path-to-workflow', required=True) +@click.option('-b', '--block-till-job-end', default=False) +def send_workflow_job_request( + address: Optional[str], + path_to_mets: str, + path_to_workflow: str, + block_till_job_end: Optional[bool] +): + client = Client(server_addr_processing=address) + workflow_job_id = client.send_workflow_job_request(path_to_wf=path_to_workflow, path_to_mets=path_to_mets) + assert workflow_job_id + print(f"Workflow job id: {workflow_job_id}") + if block_till_job_end: + client.poll_wf_status_till_timeout_fail_or_success(job_id=workflow_job_id) + + @client_cli.group('workspace') def workspace_cli(): """ diff --git a/src/ocrd_network/client.py b/src/ocrd_network/client.py index 333ec7fa44..012d2ea2e5 100644 --- a/src/ocrd_network/client.py +++ b/src/ocrd_network/client.py @@ -1,8 +1,11 @@ - from ocrd_utils import config, getLogger, LOG_FORMAT - from .client_utils import ( - poll_job_status_till_timeout_fail_or_success, post_ps_processing_request, verify_server_protocol) + poll_job_status_till_timeout_fail_or_success, + poll_wf_status_till_timeout_fail_or_success, + post_ps_processing_request, + post_ps_workflow_request, + verify_server_protocol +) class Client: @@ -10,6 +13,7 @@ def __init__(self, server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR 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 @@ -17,6 +21,14 @@ def poll_job_status_till_timeout_fail_or_success(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) + def poll_wf_status_till_timeout_fail_or_success(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) + def send_processing_job_request(self, processor_name: str, req_params: dict) -> str: return post_ps_processing_request( ps_server_host=self.server_addr_processing, processor=processor_name, job_input=req_params) + + def send_workflow_job_request(self, path_to_wf: str, path_to_mets: str): + return post_ps_workflow_request( + ps_server_host=self.server_addr_processing, path_to_wf=path_to_wf, path_to_mets=path_to_mets) diff --git a/tests/network/test_integration_6_client.py b/tests/network/test_integration_6_client.py index c1fe5ab260..fc44705b40 100644 --- a/tests/network/test_integration_6_client.py +++ b/tests/network/test_integration_6_client.py @@ -1,3 +1,4 @@ +from pathlib import Path from src.ocrd_network.constants import AgentType, JobState from tests.base import assets from tests.network.config import test_config @@ -25,4 +26,11 @@ def test_client_processing_processor(): def test_client_processing_workflow(): - pass + workspace_root = "kant_aufklaerung_1784/data" + 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) + 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)