添加进程及生命周期管理器,添加轻雪框架支持

This commit is contained in:
远野千束 2024-07-24 02:57:35 +08:00
parent 041a219151
commit 97dbf42a4d
2 changed files with 22 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import multiprocessing import multiprocessing
import time
import nonebot import nonebot
from nonebot import get_driver from nonebot import get_driver
@ -14,12 +15,19 @@ __plugin_metadata__ = PluginMetadata(
homepage="" homepage=""
) )
from src.utils import TempConfig, common_db
liteyuki = get_bot() liteyuki = get_bot()
@liteyuki.on_after_start @liteyuki.on_after_start
def _(): def _():
print("轻雪启动完成,运行在进程", multiprocessing.current_process().name) temp_data = common_db.where_one(TempConfig(), default=TempConfig())
# 储存重启信息
if temp_data.data.get("reload", False):
delta_time = time.time() - temp_data.data.get("reload_time", 0)
temp_data.data["delta_time"] = delta_time
common_db.save(temp_data) # 更新数据
@liteyuki.on_before_start @liteyuki.on_before_start

View File

@ -322,12 +322,19 @@ async def test_for_md_image(bot: T_Bot, api: str, data: dict):
@driver.on_startup @driver.on_startup
async def on_startup(): async def on_startup():
temp_data = common_db.where_one(TempConfig(), default=TempConfig()) # temp_data = common_db.where_one(TempConfig(), default=TempConfig())
# 储存重启信息 # # 储存重启信息
if temp_data.data.get("reload", False): # if temp_data.data.get("reload", False):
delta_time = time.time() - temp_data.data.get("reload_time", 0) # delta_time = time.time() - temp_data.data.get("reload_time", 0)
temp_data.data["delta_time"] = delta_time # temp_data.data["delta_time"] = delta_time
common_db.save(temp_data) # 更新数据 # common_db.save(temp_data) # 更新数据
"""
该部分迁移至轻雪生命周期
Returns:
"""
pass
@driver.on_shutdown @driver.on_shutdown