mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
close web-session on app close
This commit is contained in:
parent
3ba724e2fa
commit
a7711cc2e0
9 changed files with 37 additions and 2 deletions
|
|
@ -71,14 +71,20 @@ async def on_startup(bot: Bot) -> None:
|
|||
await bot.set_webhook(f"{BASE_WEBHOOK_URL}{WEBHOOK_PATH}", secret_token=WEBHOOK_SECRET)
|
||||
|
||||
|
||||
async def on_shutdown(bot: Bot) -> None:
|
||||
# Gracefully close web-sessions on app shutdown
|
||||
await bot.session.close()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# Dispatcher is a root router
|
||||
dp = Dispatcher()
|
||||
# ... and all other routers should be attached to Dispatcher
|
||||
dp.include_router(router)
|
||||
|
||||
# Register startup hook to initialize webhook
|
||||
# Register startup and shutdown hooks
|
||||
dp.startup.register(on_startup)
|
||||
dp.shutdown.register(on_shutdown)
|
||||
|
||||
# Initialize Bot instance with default bot properties which will be passed to all API calls
|
||||
bot = Bot(token=TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue