Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout member added to ehrclient class #89

Merged
merged 16 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions healthchain/clients/ehrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -109,14 +113,17 @@ 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
self.workflow: Workflow = workflow
self.strategy: BaseStrategy = strategy
self.vendor = None
self.request_data: List[CDSRequest] = []
self.timeout = timeout

def set_vendor(self, name) -> None:
self.vendor = name
Expand Down Expand Up @@ -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:
Expand Down
Loading