feat: added aiojobs return webhook to Telegram faster
This commit is contained in:
parent
1a5b4d0e63
commit
82d1110c68
3
bot.py
3
bot.py
|
@ -1,5 +1,6 @@
|
|||
from typing import List
|
||||
|
||||
import aiojobs as aiojobs
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.contrib.fsm_storage.redis import RedisStorage2
|
||||
from aiogram.types import ParseMode
|
||||
|
@ -31,6 +32,7 @@ async def init() -> web.Application:
|
|||
from utils.misc import logging
|
||||
import web_handlers
|
||||
logging.setup()
|
||||
scheduler = await aiojobs.create_scheduler()
|
||||
app = web.Application()
|
||||
subapps: List[str, web.Application] = [
|
||||
('/health/', web_handlers.health_app),
|
||||
|
@ -39,6 +41,7 @@ async def init() -> web.Application:
|
|||
for prefix, subapp in subapps:
|
||||
subapp['bot'] = bot
|
||||
subapp['dp'] = dp
|
||||
subapp['scheduler'] = scheduler
|
||||
app.add_subapp(prefix, subapp)
|
||||
app.on_startup.append(on_startup)
|
||||
app.on_shutdown.append(on_shutdown)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
aiomysql==0.0.20
|
||||
aiogram==2.9.2
|
||||
aiohttp==3.6.2
|
||||
aiomysql==0.0.20
|
||||
aiohttp_healthcheck==1.3.1
|
||||
aioredis==1.3.1
|
||||
loguru==0.5.1
|
||||
aiohttp_healthcheck==1.3.1
|
||||
aiojobs==0.2.2
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
from aiogram import Bot, Dispatcher, types
|
||||
from aiohttp import web
|
||||
|
||||
from loguru import logger
|
||||
|
||||
tg_updates_app = web.Application()
|
||||
|
||||
|
||||
async def execute(req: web.Request) -> web.Response:
|
||||
async def proceed_update(req: web.Request):
|
||||
upds = [types.Update(**(await req.json()))]
|
||||
Bot.set_current(req.app['bot'])
|
||||
Dispatcher.set_current(req.app['dp'])
|
||||
try:
|
||||
await req.app['dp'].process_updates(upds)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
finally:
|
||||
return web.Response()
|
||||
await req.app['dp'].process_updates(upds)
|
||||
|
||||
|
||||
async def execute(req: web.Request) -> web.Response:
|
||||
await req.app['scheduler'].spawn(proceed_update(req))
|
||||
return web.Response()
|
||||
|
||||
|
||||
tg_updates_app.add_routes([web.post('/{token}', execute)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user