Commit 77030c45 by Oleksandr Barabash

cleaner client added

parent 2640e282
...@@ -23,7 +23,7 @@ from botframework.connector import Channels ...@@ -23,7 +23,7 @@ from botframework.connector import Channels
from marshmallow import EXCLUDE from marshmallow import EXCLUDE
from bots.exceptions import ConversationNotFound from bots.exceptions import ConversationNotFound
from config import TaskModuleConfig, AppConfig from config import TaskModuleConfig, AppConfig, CLEANER_CLIENT
from entities.json.medx import MedX, MXTypes from entities.json.medx import MedX, MXTypes
from entities.json.notification import NotificationCosmos from entities.json.notification import NotificationCosmos
from entities.json.pa_message import PAMessage from entities.json.pa_message import PAMessage
...@@ -146,7 +146,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -146,7 +146,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
Log.e(TAG, "send_message::error:unknown card") Log.e(TAG, "send_message::error:unknown card")
response = await turn_context.send_activity(activity) response = await turn_context.send_activity(activity)
pa_message.message_id = response.id pa_message.message_id = response.id
await self.cosmos_client.create_pa_message(pa_message) await asyncio.gather(
self.cosmos_client.create_pa_message(pa_message),
CLEANER_CLIENT.notify_new_ttl(
pa_message.content_t_t_l.ttl
)
)
return future.set_result(response) return future.set_result(response)
else: else:
# TODO(s1z): add response!!! # TODO(s1z): add response!!!
...@@ -200,7 +205,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -200,7 +205,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
attachments=attachments) attachments=attachments)
response = await turn_context.send_activity(message) response = await turn_context.send_activity(message)
notification.message_id = response.id notification.message_id = response.id
await self.cosmos_client.create_notification(notification) await asyncio.gather(
self.cosmos_client.create_notification(notification),
CLEANER_CLIENT.notify_new_ttl(
notification.content_t_t_l.ttl
)
)
log.info(f"notification response: {response}") log.info(f"notification response: {response}")
future.set_result(notification.id) future.set_result(notification.id)
except Exception as exception: except Exception as exception:
......
...@@ -4,6 +4,7 @@ import os ...@@ -4,6 +4,7 @@ import os
from azure.cosmos import PartitionKey from azure.cosmos import PartitionKey
from utils.azure_key_vault_client import AzureKeyVaultClient from utils.azure_key_vault_client import AzureKeyVaultClient
from utils.cleaner_client import CleanerClient
from utils.cosmos_client import CosmosClient from utils.cosmos_client import CosmosClient
from utils.token_helper import TokenHelper from utils.token_helper import TokenHelper
...@@ -69,6 +70,9 @@ class AppConfig: ...@@ -69,6 +70,9 @@ class AppConfig:
BOT_NAME = os.environ.get("BOT_NAME", 'TheBot') BOT_NAME = os.environ.get("BOT_NAME", 'TheBot')
WEB_APP_NAME = os.environ.get("WEB_APP_NAME", "wa-name") WEB_APP_NAME = os.environ.get("WEB_APP_NAME", "wa-name")
WEB_APP_CLEANER_NAME = os.environ.get("WEB_APP_CLEANER_NAME",
f"wac-{WEB_APP_NAME.split('-')[1]}")
APP_ID = os.environ.get("MS_APP_ID", "app-id") APP_ID = os.environ.get("MS_APP_ID", "app-id")
APP_PASSWORD = os.environ.get("MS_APP_PASSWORD", "app-password") APP_PASSWORD = os.environ.get("MS_APP_PASSWORD", "app-password")
PA_URL = os.environ.get( PA_URL = os.environ.get(
...@@ -133,3 +137,4 @@ COSMOS_CLIENT = CosmosClient(CosmosDBConfig.HOST, CosmosDBConfig.KEY) ...@@ -133,3 +137,4 @@ COSMOS_CLIENT = CosmosClient(CosmosDBConfig.HOST, CosmosDBConfig.KEY)
KEY_VAULT_CLIENT = AzureKeyVaultClient(AppConfig.CLIENT_ID, KEY_VAULT_CLIENT = AzureKeyVaultClient(AppConfig.CLIENT_ID,
AppConfig.KEY_VAULT) AppConfig.KEY_VAULT)
TOKEN_HELPER = TokenHelper(KEY_VAULT_CLIENT) TOKEN_HELPER = TokenHelper(KEY_VAULT_CLIENT)
CLEANER_CLIENT = CleanerClient(AppConfig.WEB_APP_CLEANER_NAME)
""" Cleaner client """
import logging
import aiohttp
log = logging.getLogger()
class CleanerClient:
""" Cleaner Client class """
PATH_TTL = "/api/v1/ttl"
def __init__(self, domain_name: str):
self.domain_name = domain_name
async def notify_new_ttl(self, ttl: int):
""" Notify cleaner with the new ttl received """
url = f"{self.domain_name}{self.PATH_TTL}"
async with aiohttp.ClientSession() as session:
async with session.post(url, json=dict(ttl=ttl)) as response:
log.info(f"response: {response}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment