From 7e89fcdd9401f8559adb00fb38a83d9e288123d5 Mon Sep 17 00:00:00 2001 From: mihalin Date: Fri, 10 Sep 2021 01:06:56 +0300 Subject: [PATCH] test --- server/server.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/server.py b/server/server.py index 852d3cf..fe7e203 100644 --- a/server/server.py +++ b/server/server.py @@ -4,9 +4,9 @@ from olgram.models.models import Bot from aiohttp import web import asyncio import aiohttp - - from olgram.settings import ServerSettings +import logging +logger = logging.getLogger(__name__) def path_for_bot(bot: Bot) -> str: @@ -24,6 +24,8 @@ async def register_token(bot: Bot) -> bool: :return: получилось ли """ await unregister_token(bot.token) + + logger.info(f"register token {bot.name}") a_bot = AioBot(bot.token) res = await a_bot.set_webhook(url_for_bot(bot)) await a_bot.session.close() @@ -36,12 +38,14 @@ async def unregister_token(token: str): :param token: токен :return: """ + logger.info(f"unregister token {token}") bot = AioBot(token) await bot.session.close() await bot.delete_webhook() async def cmd_start(message, *args, **kwargs): + logger.info("cmd start") return SendMessage(chat_id=message.chat.id, text=f'Hi from webhook, bot {message.via_bot}', reply_to_message_id=message.message_id) @@ -55,6 +59,8 @@ class CustomRequestHandler(WebhookRequestHandler): async def _create_dispatcher(self): key = self.request.url.path[1:] + logger.info(f"create dispatcher {key}") + bot = await Bot.filter(code=key).first() if not bot: return None @@ -67,6 +73,7 @@ class CustomRequestHandler(WebhookRequestHandler): async def post(self): # TODO: refactor + logger.info(f"post request {self.request.url.path}") self._dispatcher = await self._create_dispatcher() res = await super(CustomRequestHandler, self).post() self._dispatcher = None @@ -78,6 +85,7 @@ class CustomRequestHandler(WebhookRequestHandler): :return: :class:`aiogram.Dispatcher` """ + logger.info("get dispatcher") return self._dispatcher @@ -89,5 +97,6 @@ def main(): runner = aiohttp.web.AppRunner(app) loop.run_until_complete(runner.setup()) + logger.info("server initialization done") site = aiohttp.web.TCPSite(runner, host=ServerSettings.app_host(), port=ServerSettings.app_port()) return site