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: 支持Graceful Shutdown(等待正在执行的matcher执行完毕后再退出) #2479

Open
ssttkkl opened this issue Dec 4, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@ssttkkl
Copy link
Contributor

ssttkkl commented Dec 4, 2023

希望能解决的问题

我有一个提供naga牌谱解析服务的插件 nonebot-plugin-nagabus 。解析需要消耗点数,换句话说就是要给naga送钱。所以希望退出时等待用户请求处理完毕再退出,否则用户消耗了点数又没拿到结果。

描述所需要的功能

当用户退出时,不希望打断当前正在执行的matcher,希望能够等待执行完毕后再退出

目前是通过hook丑陋地实现的( https://github.com/bot-ssttkkl/ssttkkl-nonebot-utils/blob/master/ssttkkl_nonebot_utils/interceptor/with_graceful_shutdown.py ),希望nb官方能够提供支持

@ssttkkl ssttkkl added the enhancement New feature or request label Dec 4, 2023
@yanyongyu
Copy link
Member

这个问题其实在之前改到结构化并发的时候就实现了,但是由于anyio的问题,这个分支最后被废弃了

@shoucandanghehe
Copy link
Contributor

我的插件目前通过hook signal handler实现了 欢迎测试(
https://github.com/shoucandanghehe/nonebot-plugin-wait-a-minute

用法:

require('nonebot_plugin_wait_a_minute')

from nonebot_plugin_wait_a_minute import graceful

@foo.handle()
@graceful()  # ← Add the decorator below the handle decorator
async def _():
    await foo.send('foo')

@ssttkkl
Copy link
Contributor Author

ssttkkl commented Oct 4, 2024

我的插件目前通过hook signal handler实现了 欢迎测试( https://github.com/shoucandanghehe/nonebot-plugin-wait-a-minute

我现在是注册了个on_shutdown的回调在里面await没执行完成的任务实现的,看起来思路都差不多(

https://github.com/bot-ssttkkl/ssttkkl-nonebot-utils/blob/master/ssttkkl_nonebot_utils/interceptor/with_graceful_shutdown.py

原来我去年说过,那没事了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants