mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-08 21:15:46 +08:00
🐛 重载时移除重复定时任务
This commit is contained in:
parent
9e1c003743
commit
819888d999
@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
@ -28,3 +29,22 @@ async def shutdown_scheduler():
|
|||||||
if scheduler.running:
|
if scheduler.running:
|
||||||
scheduler.shutdown()
|
scheduler.shutdown()
|
||||||
logger.info('定时任务结束...')
|
logger.info('定时任务结束...')
|
||||||
|
|
||||||
|
|
||||||
|
def remove_repeat_job():
|
||||||
|
repeat_jobs = {}
|
||||||
|
for i in scheduler.get_jobs():
|
||||||
|
if i.name not in repeat_jobs:
|
||||||
|
repeat_jobs[i.name] = i
|
||||||
|
else:
|
||||||
|
source_i = inspect.getsource(repeat_jobs[i.name].func)
|
||||||
|
source_j = inspect.getsource(i.func)
|
||||||
|
if source_i == source_j:
|
||||||
|
scheduler.remove_job(i.id)
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
f'发现重复函数名定时任务{i.name}, 移除该任务...'
|
||||||
|
)
|
||||||
|
scheduler.remove_job(i.id)
|
||||||
|
|
||||||
|
del repeat_jobs
|
||||||
|
@ -1,27 +1,8 @@
|
|||||||
import inspect
|
|
||||||
|
|
||||||
from gsuid_core.aps import scheduler
|
|
||||||
from gsuid_core.logger import logger
|
|
||||||
from gsuid_core.server import GsServer
|
from gsuid_core.server import GsServer
|
||||||
|
from gsuid_core.aps import remove_repeat_job
|
||||||
|
|
||||||
gss = GsServer()
|
gss = GsServer()
|
||||||
if not gss.is_load:
|
if not gss.is_load:
|
||||||
gss.is_load = True
|
gss.is_load = True
|
||||||
gss.load_plugins()
|
gss.load_plugins()
|
||||||
|
remove_repeat_job()
|
||||||
repeat_jobs = {}
|
|
||||||
for i in scheduler.get_jobs():
|
|
||||||
if i.name not in repeat_jobs:
|
|
||||||
repeat_jobs[i.name] = i
|
|
||||||
else:
|
|
||||||
source_i = inspect.getsource(repeat_jobs[i.name].func)
|
|
||||||
source_j = inspect.getsource(i.func)
|
|
||||||
if source_i == source_j:
|
|
||||||
scheduler.remove_job(i.id)
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
f'发现重复函数名定时任务{i.name}, 移除该任务...'
|
|
||||||
)
|
|
||||||
scheduler.remove_job(i.id)
|
|
||||||
|
|
||||||
del repeat_jobs
|
|
||||||
|
@ -3,6 +3,7 @@ import importlib
|
|||||||
from gsuid_core.sv import SL
|
from gsuid_core.sv import SL
|
||||||
from gsuid_core.gss import gss
|
from gsuid_core.gss import gss
|
||||||
from gsuid_core.logger import logger
|
from gsuid_core.logger import logger
|
||||||
|
from gsuid_core.aps import remove_repeat_job
|
||||||
|
|
||||||
|
|
||||||
def reload_plugin(plugin_name: str):
|
def reload_plugin(plugin_name: str):
|
||||||
@ -24,11 +25,16 @@ def reload_plugin(plugin_name: str):
|
|||||||
del SL.plugins[plugin_name]
|
del SL.plugins[plugin_name]
|
||||||
|
|
||||||
retcode = gss.load_plugin(plugin_name)
|
retcode = gss.load_plugin(plugin_name)
|
||||||
|
if retcode is None:
|
||||||
|
logger.info(f'❌ 未知的插件类型{plugin_name}...')
|
||||||
|
return '未知错误, 请检查控制台...'
|
||||||
|
|
||||||
if isinstance(retcode, str):
|
if isinstance(retcode, str):
|
||||||
logger.info(f'❌ 重载插件{plugin_name}失败...')
|
logger.info(f'❌ 重载插件{plugin_name}失败...')
|
||||||
return retcode
|
return retcode
|
||||||
else:
|
else:
|
||||||
for module in retcode:
|
for module in retcode:
|
||||||
importlib.reload(module)
|
importlib.reload(module)
|
||||||
|
remove_repeat_job()
|
||||||
logger.info(f'✨ 已重载插件{plugin_name}')
|
logger.info(f'✨ 已重载插件{plugin_name}')
|
||||||
return f'✨ 已重载插件{plugin_name}!'
|
return f'✨ 已重载插件{plugin_name}!'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user