Skip to content

Commit

Permalink
implement feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Oct 1, 2024
1 parent b183cfc commit 342ef3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/ocrd_network/cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand All @@ -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')
Expand Down
12 changes: 5 additions & 7 deletions src/ocrd_network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions src/ocrd_network/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions src/ocrd_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ''))
Expand Down

0 comments on commit 342ef3a

Please sign in to comment.