mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
add async queue
This commit is contained in:
parent
4f9c0aa1f7
commit
fec8923eed
@ -2,7 +2,6 @@ import asyncio
|
|||||||
import sys
|
import sys
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from aiogram.types import Update
|
from aiogram.types import Update
|
||||||
@ -23,7 +22,7 @@ from app.settings import (
|
|||||||
WEBHOOK_URL,
|
WEBHOOK_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
queue: Any = asyncio.Queue()
|
queue: asyncio.Queue = asyncio.Queue() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
async def bot_startup() -> None:
|
async def bot_startup() -> None:
|
||||||
@ -88,6 +87,7 @@ async def webhook(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(tg_update)
|
||||||
return web.Response(status=HTTPStatus.ACCEPTED)
|
return web.Response(status=HTTPStatus.ACCEPTED)
|
||||||
|
|
||||||
|
|
||||||
@ -97,6 +97,7 @@ async def worker() -> None:
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
update = await queue.get()
|
update = await queue.get()
|
||||||
|
logger.warning(f"Get update {update}")
|
||||||
await dispatcher.process_update(update)
|
await dispatcher.process_update(update)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user