定时作业添加提供者条目
This commit is contained in:
parent
f23cab861a
commit
185c78b05c
@ -246,6 +246,16 @@ class PluginManager(metaclass=Singleton):
|
|||||||
ret_services.extend(services)
|
ret_services.extend(services)
|
||||||
return ret_services
|
return ret_services
|
||||||
|
|
||||||
|
def get_plugin_attr(self, pid: str, attr: str) -> Any:
|
||||||
|
"""
|
||||||
|
获取插件属性
|
||||||
|
"""
|
||||||
|
if not self._running_plugins.get(pid):
|
||||||
|
return None
|
||||||
|
if not hasattr(self._running_plugins[pid], attr):
|
||||||
|
return None
|
||||||
|
return getattr(self._running_plugins[pid], attr)
|
||||||
|
|
||||||
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
||||||
"""
|
"""
|
||||||
运行插件方法
|
运行插件方法
|
||||||
|
@ -284,6 +284,8 @@ class Scheduler(metaclass=Singleton):
|
|||||||
plugin_services = PluginManager().run_plugin_method(pid, "get_service") or []
|
plugin_services = PluginManager().run_plugin_method(pid, "get_service") or []
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
# 获取插件名称
|
||||||
|
plugin_name = PluginManager().get_plugin_attr(pid, "plugin_name")
|
||||||
# 开始注册插件服务
|
# 开始注册插件服务
|
||||||
for service in plugin_services:
|
for service in plugin_services:
|
||||||
try:
|
try:
|
||||||
@ -292,6 +294,7 @@ class Scheduler(metaclass=Singleton):
|
|||||||
"func": service["func"],
|
"func": service["func"],
|
||||||
"name": service["name"],
|
"name": service["name"],
|
||||||
"pid": pid,
|
"pid": pid,
|
||||||
|
"plugin_name": plugin_name,
|
||||||
"running": False,
|
"running": False,
|
||||||
}
|
}
|
||||||
self._scheduler.add_job(
|
self._scheduler.add_job(
|
||||||
@ -304,7 +307,7 @@ class Scheduler(metaclass=Singleton):
|
|||||||
'job_id': sid
|
'job_id': sid
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
logger.info(f"注册插件服务({pid}):{service['name']}")
|
logger.info(f"注册插件服务({plugin_name}):{service['name']}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"注册插件服务失败:{str(e)} - {service}")
|
logger.error(f"注册插件服务失败:{str(e)} - {service}")
|
||||||
|
|
||||||
@ -313,6 +316,8 @@ class Scheduler(metaclass=Singleton):
|
|||||||
移除插件定时服务
|
移除插件定时服务
|
||||||
"""
|
"""
|
||||||
with self._lock:
|
with self._lock:
|
||||||
|
# 获取插件名称
|
||||||
|
plugin_name = PluginManager().get_plugin_attr(pid, "plugin_name")
|
||||||
for job_id, service in self._jobs.copy().items():
|
for job_id, service in self._jobs.copy().items():
|
||||||
try:
|
try:
|
||||||
if service.get("pid") == pid:
|
if service.get("pid") == pid:
|
||||||
@ -321,7 +326,7 @@ class Scheduler(metaclass=Singleton):
|
|||||||
self._scheduler.remove_job(job_id)
|
self._scheduler.remove_job(job_id)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
logger.info(f"移除插件服务({pid}):{service.get('name')}")
|
logger.info(f"移除插件服务({plugin_name}):{service.get('name')}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"移除插件服务失败:{str(e)} - {job_id}: {service}")
|
logger.error(f"移除插件服务失败:{str(e)} - {job_id}: {service}")
|
||||||
|
|
||||||
@ -338,16 +343,14 @@ class Scheduler(metaclass=Singleton):
|
|||||||
# 按照下次运行时间排序
|
# 按照下次运行时间排序
|
||||||
jobs.sort(key=lambda x: x.next_run_time)
|
jobs.sort(key=lambda x: x.next_run_time)
|
||||||
# 将正在运行的任务提取出来 (保障一次性任务正常显示)
|
# 将正在运行的任务提取出来 (保障一次性任务正常显示)
|
||||||
for job_id, value in self._jobs.items():
|
for job_id, service in self._jobs.items():
|
||||||
name = value.get("name")
|
name = service.get("name")
|
||||||
if value.get("running") and name:
|
plugin_name = service.get("plugin_name")
|
||||||
if name not in added:
|
if service.get("running") and name and plugin_name:
|
||||||
added.append(name)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
schedulers.append(schemas.ScheduleInfo(
|
schedulers.append(schemas.ScheduleInfo(
|
||||||
id=job_id,
|
id=job_id,
|
||||||
name=name,
|
name=name,
|
||||||
|
provider=plugin_name,
|
||||||
status="正在运行",
|
status="正在运行",
|
||||||
next_run="~"
|
next_run="~"
|
||||||
))
|
))
|
||||||
@ -358,15 +361,17 @@ class Scheduler(metaclass=Singleton):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
job_id = job.id.split("|")[0]
|
job_id = job.id.split("|")[0]
|
||||||
if not self._jobs.get(job_id):
|
service = self._jobs.get(job_id)
|
||||||
|
if not service:
|
||||||
continue
|
continue
|
||||||
# 任务状态
|
# 任务状态
|
||||||
status = "正在运行" if self._jobs[job_id].get("running") else "等待"
|
status = "正在运行" if service.get("running") else "等待"
|
||||||
# 下次运行时间
|
# 下次运行时间
|
||||||
next_run = TimerUtils.time_difference(job.next_run_time)
|
next_run = TimerUtils.time_difference(job.next_run_time)
|
||||||
schedulers.append(schemas.ScheduleInfo(
|
schedulers.append(schemas.ScheduleInfo(
|
||||||
id=job_id,
|
id=job_id,
|
||||||
name=job.name,
|
name=job.name,
|
||||||
|
provider=service.get("plugin_name", "MoviePilot"),
|
||||||
status=status,
|
status=status,
|
||||||
next_run=next_run
|
next_run=next_run
|
||||||
))
|
))
|
||||||
|
@ -56,6 +56,8 @@ class ScheduleInfo(BaseModel):
|
|||||||
id: Optional[str] = None
|
id: Optional[str] = None
|
||||||
# 名称
|
# 名称
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
|
# 提供者
|
||||||
|
provider: Optional[str] = None
|
||||||
# 状态
|
# 状态
|
||||||
status: Optional[str] = None
|
status: Optional[str] = None
|
||||||
# 下次执行时间
|
# 下次执行时间
|
||||||
|
Loading…
x
Reference in New Issue
Block a user