Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 优化 Bot 连接与断开时机 #26

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

T0nyX1ang
Copy link
Contributor

@T0nyX1ang T0nyX1ang commented Nov 16, 2023

目前 adapter-console 上报 Bot 断开的时机需要在终端断开且按下 Ctrl-C 之后,这将导致终端断开以后,彻底终止程序之前,与定时任务相关的所有行为无法被暂停。因此,本提交将上报 Bot 断开的时机前移到了终端断开时刻 (on_console_unmount),同时为了对称,把上报 Bot 连接的时机推迟到了终端挂载时刻 (on_console_mount)。该提交将能使 Driver.bot_disconnect 装饰器生效,从而使得定时任务能够提前关闭。

从日志分析而言,会将程序流程从:

[INFO] uvicorn | Application startup complete.
[INFO] uvicorn | Uvicorn running on xxxxx (Press CTRL+C to quit)
[WARNING] nonebot | Press Ctrl-C for Application exit
[INFO] uvicorn | Shutting down
[INFO] uvicorn | Waiting for application shutdown.
[INFO] nonebot_plugin_apscheduler | Scheduler Shutdown
[DEBUG] nonebot | Waiting for running bot connection hooks...
[INFO] uvicorn | Application shutdown complete.

变为:

[INFO] uvicorn | Application startup complete.
[INFO] uvicorn | Uvicorn running on xxxxx (Press CTRL+C to quit)
[SUCCESS] nonebot | Console mounted.
[SUCCESS] nonebot | Console unmounted.
[WARNING] nonebot | Press Ctrl-C for Application exit
[INFO] uvicorn | Shutting down
[INFO] uvicorn | Waiting for application shutdown.
[INFO] nonebot_plugin_apscheduler | Scheduler Shutdown
[INFO] uvicorn | Application shutdown complete.

@yanyongyu yanyongyu changed the title 🎨 优化Bot连接与断开上报时机 Feature: 优化 Bot 连接与断开时机 Nov 17, 2023
@RF-Tar-Railt RF-Tar-Railt merged commit 70c1b0c into nonebot:master Nov 17, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants