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

refactor: handle async context manager in clientlet #6194

Merged
merged 1 commit into from
Sep 10, 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
21 changes: 13 additions & 8 deletions jina/clients/base/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ async def send_message(self, request: 'Request'):
from docarray.base_doc.io.json import orjson_dumps

request_kwargs['data'] = JinaJsonPayload(value=req_dict)
response = await self.session.post(**request_kwargs).__aenter__()
try:
r_str = await response.json()
except aiohttp.ContentTypeError:
r_str = await response.text()
handle_response_status(response.status, r_str, self.url)
return response
except (ValueError, ConnectionError, BadClient, aiohttp.ClientError) as err:
async with self.session.post(**request_kwargs) as response:
try:
r_str = await response.json()
except aiohttp.ContentTypeError:
r_str = await response.text()
handle_response_status(response.status, r_str, self.url)
return response
except (ValueError, ConnectionError, BadClient, aiohttp.ClientError, aiohttp.ClientConnectionError) as err:
self.logger.debug(f'Got an error: {err} sending POST to {self.url} in attempt {attempt}/{self.max_attempts}')
await retry.wait_or_raise_err(
attempt=attempt,
err=err,
Expand All @@ -189,6 +190,10 @@ async def send_message(self, request: 'Request'):
initial_backoff=self.initial_backoff,
max_backoff=self.max_backoff,
)
except Exception as exc:
self.logger.debug(
f'Got a non-retried error: {exc} sending POST to {self.url}')
raise exc

async def send_streaming_message(self, doc: 'Document', on: str):
"""Sends a GET SSE request to the server
Expand Down
Loading