Skip to content

Commit

Permalink
add timeout and wait to configs
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Aug 9, 2024
1 parent 3a238a7 commit 50794f9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/ocrd_network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@


class Client:
def __init__(self, server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR_PROCESSING):
def __init__(
self,
server_addr_processing: str = config.OCRD_NETWORK_SERVER_ADDR_PROCESSING,
timeout: int = config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT,
wait: int = config.OCRD_NETWORK_CLIENT_POLLING_SLEEP
):
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
self.polling_timeout = timeout
self.polling_wait = wait
self.polling_tries = int(timeout/wait)

def poll_job_status_till_timeout_fail_or_success(self, job_id: str) -> str:
return poll_job_status_till_timeout_fail_or_success(
Expand Down
10 changes: 10 additions & 0 deletions src/ocrd_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ def _ocrd_download_timeout_parser(val):
description="Default address of Processing Server to connect to (for `ocrd network client processing`).",
default=(True, ''))

config.add("OCRD_NETWORK_CLIENT_POLLING_TIMEOUT",
description="Timeout for a blocking ocrd network client (seconds)",
parser=int,
default=(True, 3600))

config.add("OCRD_NETWORK_CLIENT_POLLING_SLEEP",
description="How many seconds to sleep before trying again (seconds)",
parser=int,
default=(True, 30))

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
14 changes: 14 additions & 0 deletions tests/network/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@
parser=_ocrd_download_timeout_parser
)

test_config.add(
"OCRD_NETWORK_CLIENT_POLLING_TIMEOUT",
description="Timeout for a blocking ocrd network client",
parser=int,
default=(True, 3600)
)

test_config.add(
"OCRD_NETWORK_CLIENT_POLLING_SLEEP",
description="How many seconds to sleep before trying again (seconds)",
parser=int,
default=(True, 30)
)

test_config.add(
name="OCRD_NETWORK_SERVER_ADDR_PROCESSING",
description="Default address of Processing Server to connect to (for `ocrd network client processing`).",
Expand Down
6 changes: 4 additions & 2 deletions tests/network/test_integration_6_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from ocrd_network.client import Client

PROCESSING_SERVER_URL = test_config.PROCESSING_SERVER_URL
timeout = test_config.OCRD_NETWORK_CLIENT_POLLING_TIMEOUT
wait = test_config.OCRD_NETWORK_CLIENT_POLLING_SLEEP


def test_client_processing_processor():
workspace_root = "kant_aufklaerung_1784/data"
path_to_mets = assets.path_to(f"{workspace_root}/mets.xml")
client = Client(server_addr_processing=PROCESSING_SERVER_URL)
client = Client(PROCESSING_SERVER_URL, timeout, wait)
req_params = {
"path_to_mets": path_to_mets,
"description": "OCR-D Network client request",
Expand All @@ -30,7 +32,7 @@ def test_client_processing_workflow():
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)
client = Client(PROCESSING_SERVER_URL, timeout, wait)
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 50794f9

Please sign in to comment.