mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
roll back queue
This commit is contained in:
parent
04d31b0e24
commit
5f00cb0c1e
22
app/main.py
22
app/main.py
@ -22,16 +22,11 @@ from app.settings import (
|
||||
WEBHOOK_URL,
|
||||
)
|
||||
|
||||
queue: asyncio.Queue = asyncio.Queue() # type: ignore
|
||||
|
||||
|
||||
async def bot_startup() -> None:
|
||||
await bot.set_webhook(WEBHOOK_URL)
|
||||
logger.info(f'Webhook set to {WEBHOOK_URL}'.replace(API_TOKEN, '{BOT_API_TOKEN}'))
|
||||
asyncio_schedule()
|
||||
logger.info('Scheduler started')
|
||||
await worker()
|
||||
logger.info('Worker started')
|
||||
|
||||
|
||||
async def bot_shutdown() -> None:
|
||||
@ -88,22 +83,13 @@ async def webhook(request: web.Request) -> web.Response:
|
||||
"""
|
||||
data = await request.json()
|
||||
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)
|
||||
Bot.set_current(dispatcher.bot)
|
||||
await asyncio.sleep(3)
|
||||
logger.info('Worker is working')
|
||||
while True:
|
||||
await asyncio.sleep(4)
|
||||
update = await queue.get()
|
||||
logger.warning(f"Get update {update}")
|
||||
await dispatcher.process_update(update)
|
||||
|
||||
await dispatcher.process_update(tg_update)
|
||||
|
||||
return web.Response(status=HTTPStatus.OK)
|
||||
|
||||
|
||||
async def create_app() -> web.Application:
|
||||
|
Loading…
x
Reference in New Issue
Block a user