Skip to content

Commit

Permalink
refactor: handle async context manager in clientlet (#6194)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM authored Sep 10, 2024
1 parent dbb6243 commit 533a7d8
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit 533a7d8

Please sign in to comment.