π LifespanΒΆ
Raito lets you define async startup/shutdown logic using a @rt.lifespan(router) decorator β just like in FastAPI.
ExampleΒΆ
from typing import AsyncGenerator
from aiogram import Bot, Router,
from raito import rt, Raito
router = Router(name="lifespan")
@rt.lifespan(router)
async def lifespan_fn(raito: Raito, bot: Bot):
bot_info = await bot.get_me()
rt.log.info("π Launching bot : [@%s] %s", bot_info.username, bot_info.full_name)
rt.debug("Registering commands...")
await raito.register_commands(bot)
yield
rt.log.info("π Bye!")
How it worksΒΆ
Code before
yieldruns on startupCode after
yieldruns on shutdownLifespans are tracked per
bot.idand executed in reverse order on exit