Skip to content

Commit e9610a7

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/npm_and_yarn-3c67cbb9cd
2 parents 8a4c9a2 + 679d0c7 commit e9610a7

File tree

4 files changed

+9
-62
lines changed

4 files changed

+9
-62
lines changed

services/web/server/src/simcore_service_webserver/chatbot/_client.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44
import httpx
55
from aiohttp import web
66
from pydantic import BaseModel, Field
7-
from servicelib.aiohttp import status
87
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
9-
from tenacity import (
10-
retry,
11-
retry_if_exception_type,
12-
retry_if_result,
13-
stop_after_attempt,
14-
wait_exponential,
15-
)
168

179
from .settings import ChatbotSettings, get_plugin_settings
1810

@@ -23,33 +15,6 @@ class ChatResponse(BaseModel):
2315
answer: Annotated[str, Field(description="Answer from the chatbot")]
2416

2517

26-
def _should_retry(response: httpx.Response | None) -> bool:
27-
if response is None:
28-
return True
29-
return (
30-
response.status_code >= status.HTTP_500_INTERNAL_SERVER_ERROR
31-
or response.status_code == status.HTTP_429_TOO_MANY_REQUESTS
32-
)
33-
34-
35-
_CHATBOT_RETRY = retry(
36-
retry=(
37-
retry_if_result(_should_retry)
38-
| retry_if_exception_type(
39-
(
40-
httpx.ConnectError,
41-
httpx.TimeoutException,
42-
httpx.NetworkError,
43-
httpx.ProtocolError,
44-
)
45-
)
46-
),
47-
stop=stop_after_attempt(3),
48-
wait=wait_exponential(multiplier=1, min=1, max=10),
49-
reraise=True,
50-
)
51-
52-
5318
class ChatbotRestClient:
5419
def __init__(self, chatbot_settings: ChatbotSettings) -> None:
5520
self._client = httpx.AsyncClient()
@@ -59,7 +24,6 @@ async def get_settings(self) -> dict[str, Any]:
5924
"""Fetches chatbot settings"""
6025
url = httpx.URL(self._chatbot_settings.base_url).join("/v1/chat/settings")
6126

62-
@_CHATBOT_RETRY
6327
async def _request() -> httpx.Response:
6428
return await self._client.get(url)
6529

@@ -78,7 +42,6 @@ async def ask_question(self, question: str) -> ChatResponse:
7842
"""Asks a question to the chatbot"""
7943
url = httpx.URL(self._chatbot_settings.base_url).join("/v1/chat")
8044

81-
@_CHATBOT_RETRY
8245
async def _request() -> httpx.Response:
8346
return await self._client.post(
8447
url,
@@ -103,14 +66,6 @@ async def _request() -> httpx.Response:
10366
)
10467
raise
10568

106-
async def __aenter__(self):
107-
"""Async context manager entry"""
108-
return self
109-
110-
async def __aexit__(self, exc_type, exc_val, exc_tb):
111-
"""Async context manager exit - cleanup client"""
112-
await self._client.aclose()
113-
11469

11570
_APPKEY: Final = web.AppKey(ChatbotRestClient.__name__, ChatbotRestClient)
11671

services/web/server/src/simcore_service_webserver/chatbot/_process_chatbot_trigger_service.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from models_library.rabbitmq_messages import WebserverChatbotRabbitMessage
1010
from models_library.rest_ordering import OrderBy, OrderDirection
1111
from pydantic import TypeAdapter
12-
from servicelib.logging_utils import log_catch, log_context
12+
from servicelib.logging_utils import log_context
1313
from servicelib.rabbitmq import RabbitMQClient
1414

1515
from ..conversations import conversations_service
@@ -32,6 +32,11 @@ async def _process_chatbot_trigger_message(app: web.Application, data: bytes) ->
3232
rabbit_message = TypeAdapter(WebserverChatbotRabbitMessage).validate_json(data)
3333
assert app # nosec
3434

35+
_logger.info(
36+
"Processing chatbot trigger message for conversation ID=%s",
37+
rabbit_message.conversation.conversation_id,
38+
)
39+
3540
_product_name = rabbit_message.conversation.product_name
3641
_product = products_service.get_product(app, product_name=_product_name)
3742

@@ -102,19 +107,7 @@ async def _subscribe_to_rabbitmq(app) -> str:
102107

103108

104109
async def _unsubscribe_from_rabbitmq(app) -> None:
105-
with (
106-
log_context(
107-
_logger,
108-
logging.INFO,
109-
msg=f"Unsubscribing from {WebserverChatbotRabbitMessage.get_channel_name()} channel",
110-
),
111-
log_catch(_logger, reraise=False),
112-
):
113-
rabbit_client: RabbitMQClient = get_rabbitmq_client(app)
114-
if app[_RABBITMQ_WEBSERVER_CHATBOT_CONSUMER_APPKEY]:
115-
await rabbit_client.unsubscribe(
116-
app[_RABBITMQ_WEBSERVER_CHATBOT_CONSUMER_APPKEY]
117-
)
110+
assert app # nosec
118111

119112

120113
async def on_cleanup_ctx_rabbitmq_consumer(

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def list_(
101101
)
102102
list_query = list_query.offset(offset).limit(limit)
103103

104-
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
104+
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
105105
total_count = await conn.scalar(count_query)
106106

107107
result = await conn.stream(list_query)

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ async def create_support_message(
264264
"Support settings NOT available, so no need to create FogBugz case. Conversation ID: %s",
265265
conversation.conversation_id,
266266
)
267-
return message
268267

269-
if is_first_message or conversation.fogbugz_case_id is None:
268+
elif is_first_message or conversation.fogbugz_case_id is None:
270269
_logger.info(
271270
"Support settings available, this is first message, creating FogBugz case for Conversation ID: %s",
272271
conversation.conversation_id,

0 commit comments

Comments
 (0)