mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-08 10:39:59 +00:00
- 移除原监控仪表盘独立模块,将相关功能合并到在线监控模块 - 重构租户配置字段名,统一使用logo_url和name替代tenant_logo/tenant_name - 优化搜索工具函数,移除重复导入 - 调整参数配置模型字段长度限制,移除config_value的max_length约束 - 清理冗余的常量定义和导入语句 - 修复批量状态设置接口的redis依赖注入 - 增强OAuth登录安全性,添加租户默认归属和state一次性消费 - 优化资源目录缓存逻辑,减少重复计算 - 新增API Token模块基础框架 - 完善用户token版本管理,支持主动失效JWT - 调整AI模型配置缓存过期时间 - 修复菜单类型字段索引,提升查询性能 - 简化前端刷新token调用逻辑 - 新增滑块验证完成接口和忘记密码验证码校验 - 调整系统配置默认值,添加操作日志保留天数和接口白名单配置 - 限制Mock支付回调仅在开发环境可用 - 重构websocket认证方式,支持更安全的subprotocol传参
118 lines
3.9 KiB
Python
118 lines
3.9 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.ap_scheduler import SchedulerUtil
|
|
from app.core.base_schema import AuthSchema, PageResultSchema
|
|
from app.core.exceptions import CustomException
|
|
from app.utils.common_util import search_to_dict
|
|
|
|
from .crud import JobCRUD
|
|
from .schema import JobCreateSchema, JobOutSchema, JobQueryParam, JobUpdateSchema
|
|
|
|
|
|
class JobService:
|
|
"""调度器监控模块服务层"""
|
|
|
|
def __init__(self, auth: AuthSchema, db: AsyncSession) -> None:
|
|
self.auth = auth
|
|
self.db = db
|
|
|
|
async def get_job_log_detail(self, id: int) -> JobOutSchema:
|
|
obj = await JobCRUD(self.auth, self.db).get_obj_by_id_crud(id=id)
|
|
if not obj:
|
|
raise CustomException(msg="执行日志不存在")
|
|
return JobOutSchema.model_validate(obj)
|
|
|
|
async def get_job_log_list(
|
|
self,
|
|
search: JobQueryParam | None = None,
|
|
order_by: list[dict[str, str]] | None = None,
|
|
) -> list[JobOutSchema]:
|
|
if order_by is None:
|
|
order_by = [{"created_time": "desc"}]
|
|
obj_list = await JobCRUD(self.auth, self.db).get_obj_list_crud(search=search_to_dict(search, {}), order_by=order_by)
|
|
return [JobOutSchema.model_validate(obj) for obj in obj_list]
|
|
|
|
async def get_job_log_page(
|
|
self,
|
|
page_no: int,
|
|
page_size: int,
|
|
search: JobQueryParam | None = None,
|
|
order_by: list[dict[str, str]] | None = None,
|
|
) -> PageResultSchema[JobOutSchema]:
|
|
offset = (page_no - 1) * page_size
|
|
ob = order_by or [{"created_time": "desc"}]
|
|
return await JobCRUD(self.auth, self.db).page(
|
|
offset=offset,
|
|
limit=page_size,
|
|
order_by=ob,
|
|
search=search_to_dict(search, {}),
|
|
out_schema=JobOutSchema,
|
|
)
|
|
|
|
async def create_job_log(
|
|
self,
|
|
job_id: str,
|
|
job_name: str | None = None,
|
|
trigger_type: str | None = None,
|
|
) -> JobOutSchema:
|
|
data = JobCreateSchema(
|
|
job_id=job_id,
|
|
job_name=job_name,
|
|
trigger_type=trigger_type,
|
|
status=1, # 执行中
|
|
)
|
|
obj = await JobCRUD(self.auth, self.db).create_obj_crud(data=data)
|
|
if not obj:
|
|
raise CustomException(msg="创建执行日志失败")
|
|
return JobOutSchema.model_validate(obj)
|
|
|
|
async def update_job_log(
|
|
self,
|
|
id: int,
|
|
status: int,
|
|
result: str | None = None,
|
|
error: str | None = None,
|
|
) -> JobOutSchema:
|
|
data = JobUpdateSchema(
|
|
status=status,
|
|
result=result,
|
|
error=error,
|
|
)
|
|
obj = await JobCRUD(self.auth, self.db).update_obj_crud(id=id, data=data)
|
|
if not obj:
|
|
raise CustomException(msg="更新执行日志失败")
|
|
return JobOutSchema.model_validate(obj)
|
|
|
|
async def delete_job_log(self, ids: list[int]) -> None:
|
|
if not ids:
|
|
raise CustomException(msg="删除失败,删除对象不能为空")
|
|
await JobCRUD(self.auth, self.db).delete_obj_crud(ids=ids)
|
|
|
|
async def clear_job_log(self) -> None:
|
|
await JobCRUD(self.auth, self.db).clear_obj_crud()
|
|
|
|
@staticmethod
|
|
def get_scheduler_status() -> dict:
|
|
status = SchedulerUtil.get_scheduler_state()
|
|
is_running = SchedulerUtil.is_running()
|
|
jobs = SchedulerUtil.get_all_jobs()
|
|
return {
|
|
"status": status,
|
|
"is_running": is_running,
|
|
"job_count": len(jobs),
|
|
}
|
|
|
|
@staticmethod
|
|
def get_scheduler_jobs() -> list[dict]:
|
|
jobs = SchedulerUtil.get_all_jobs()
|
|
return [
|
|
{
|
|
"id": job.id,
|
|
"name": job.name,
|
|
"trigger": str(job.trigger),
|
|
"next_run_time": str(job.next_run_time) if job.next_run_time else None,
|
|
"status": SchedulerUtil.get_job_status(job_id=job.id),
|
|
}
|
|
for job in jobs
|
|
]
|