Skip to content

Commit

Permalink
add: client workflow run
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Aug 9, 2024
1 parent 2a843a8 commit 3a238a7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
21 changes: 20 additions & 1 deletion src/ocrd_network/cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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():
"""
Expand Down
18 changes: 15 additions & 3 deletions src/ocrd_network/client.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@

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:
def __init__(self, server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR_PROCESSING):
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

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)
10 changes: 9 additions & 1 deletion tests/network/test_integration_6_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 3a238a7

Please sign in to comment.