add queue to bot

This commit is contained in:
Dmitry Afanasyev 2022-08-21 23:23:52 +03:00
parent 95af779729
commit 61d6826f24

View File

@ -3,7 +3,7 @@ import sys
from http import HTTPStatus from http import HTTPStatus
from pathlib import Path from pathlib import Path
from aiogram import Bot, Dispatcher from aiogram import Dispatcher
from aiogram.types import Update from aiogram.types import Update
from aiogram.utils.executor import start_polling from aiogram.utils.executor import start_polling
from aiohttp import web from aiohttp import web
@ -88,19 +88,16 @@ async def put_updates_on_queue(request: web.Request) -> web.Response:
data = await request.json() data = await request.json()
tg_update = Update(**data) tg_update = Update(**data)
queue.put_nowait(tg_update) queue.put_nowait(tg_update)
logger.info(queue.__dict__)
return web.Response(status=HTTPStatus.ACCEPTED) return web.Response(status=HTTPStatus.ACCEPTED)
async def get_updates_from_queue() -> None: async def get_updates_from_queue() -> None:
update = await queue.get()
Dispatcher.set_current(dispatcher) while True:
Bot.set_current(dispatcher.bot) update = await queue.get()
await dispatcher.process_update(update)
await dispatcher.process_update(update) await asyncio.sleep(0.1)
await asyncio.sleep(0.2)
async def create_app() -> web.Application: async def create_app() -> web.Application: