roll back queue

This commit is contained in:
Dmitry Afanasyev 2022-08-20 01:30:55 +03:00
parent 04d31b0e24
commit 5f00cb0c1e

View File

@ -22,16 +22,11 @@ from app.settings import (
WEBHOOK_URL, WEBHOOK_URL,
) )
queue: asyncio.Queue = asyncio.Queue() # type: ignore
async def bot_startup() -> None: async def bot_startup() -> None:
await bot.set_webhook(WEBHOOK_URL) await bot.set_webhook(WEBHOOK_URL)
logger.info(f'Webhook set to {WEBHOOK_URL}'.replace(API_TOKEN, '{BOT_API_TOKEN}')) logger.info(f'Webhook set to {WEBHOOK_URL}'.replace(API_TOKEN, '{BOT_API_TOKEN}'))
asyncio_schedule() asyncio_schedule()
logger.info('Scheduler started')
await worker()
logger.info('Worker started')
async def bot_shutdown() -> None: async def bot_shutdown() -> None:
@ -88,22 +83,13 @@ async def webhook(request: web.Request) -> web.Response:
""" """
data = await request.json() data = await request.json()
tg_update = Update(**data) tg_update = Update(**data)
logger.info(tg_update)
queue.put_nowait(tg_update)
logger.info('Put in queue')
return web.Response(status=HTTPStatus.ACCEPTED)
async def worker() -> None:
Dispatcher.set_current(dispatcher) Dispatcher.set_current(dispatcher)
Bot.set_current(dispatcher.bot) Bot.set_current(dispatcher.bot)
await asyncio.sleep(3)
logger.info('Worker is working') await dispatcher.process_update(tg_update)
while True:
await asyncio.sleep(4) return web.Response(status=HTTPStatus.OK)
update = await queue.get()
logger.warning(f"Get update {update}")
await dispatcher.process_update(update)
async def create_app() -> web.Application: async def create_app() -> web.Application: