From ed7c69f4b68f5b26a66c5b9fd5590b18684a4b92 Mon Sep 17 00:00:00 2001 From: Anshuman Laskar <101874272+Vortex-21@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:22:05 +0530 Subject: [PATCH] Timeout member added to ehrclient class (#89) * Overflow and Type Errors added to concept.py . Required tests for quantity class added in tests. * minor issues fixed * code formatted * python-version file removed * Removed TypeError for None and updated tests * test_cdaannotator updated * cdaannotator updated with find various sections using codes functionality * timeout member added to ehrclient class * docstring updated! * updated docstring --------- Co-authored-by: Adam Kells --- healthchain/clients/ehrclient.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/healthchain/clients/ehrclient.py b/healthchain/clients/ehrclient.py index bba59b5..1bd12c4 100644 --- a/healthchain/clients/ehrclient.py +++ b/healthchain/clients/ehrclient.py @@ -99,7 +99,11 @@ def wrapper(self, *args: Any, **kwargs: Any) -> EHRClient: class EHRClient(BaseClient): def __init__( - self, func: Callable[..., Any], workflow: Workflow, strategy: BaseStrategy + self, + func: Callable[..., Any], + workflow: Workflow, + strategy: BaseStrategy, + timeout: Optional[float] = 10.0, ): """ Initializes the EHRClient with a data generator function and optional workflow and use case. @@ -109,7 +113,9 @@ def __init__( func (Callable[..., Any]): A function to generate data for requests. workflow ([Workflow]): The workflow context to apply to the data generator. strategy (BaseStrategy): The strategy object to construct requests based on the generated data. - + timeout(Optional[float], default=10.0) : The maximum time in seconds to wait for a response from the server. + This parameter determines how long the client will wait before considering a request timed out. + A higher timeout value allows for longer-running operations, while a lower value prioritizes faster responses. """ # TODO: Add option to pass in different provider options self.data_generator_func: Callable[..., Any] = func @@ -117,6 +123,7 @@ def __init__( self.strategy: BaseStrategy = strategy self.vendor = None self.request_data: List[CDSRequest] = [] + self.timeout = timeout def set_vendor(self, name) -> None: self.vendor = name @@ -150,7 +157,7 @@ async def send_request(self, url: str) -> List[Dict]: async with httpx.AsyncClient() as client: responses: List[Dict] = [] # TODO: pass timeout as config - timeout = httpx.Timeout(10.0, read=None) + timeout = httpx.Timeout(self.timeout, read=None) for request in self.request_data: try: if self.strategy.api_protocol == ApiProtocol.soap: