优化任务管理

This commit is contained in:
ryan
2026-06-10 19:27:51 +08:00
parent 69edb1252b
commit db163034c0
24 changed files with 2063 additions and 131 deletions
+363
View File
@@ -1659,6 +1659,287 @@ const docTemplate = `{
}
}
},
"/api/v1/admin/tasks/schedules": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "返回系统所有的定时任务配置列表,包括名称、关联的异步任务类型、Cron 表达式和启用状态,需要管理员权限",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "获取定时任务列表",
"responses": {
"200": {
"description": "定时任务列表",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/model.Schedule"
}
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
},
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "新增一个动态定时任务配置,关联已有的异步任务,配置 Cron 表达式和执行参数,并触发调度器热加载,需要管理员权限",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "创建定时任务",
"parameters": [
{
"description": "创建定时任务请求参数",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/task.CreateScheduleRequest"
}
}
],
"responses": {
"200": {
"description": "创建成功的定时任务信息",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.Schedule"
}
}
}
]
}
},
"400": {
"description": "Cron 表达式无效、异步任务类型不存在或参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "保存定时任务失败",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/tasks/schedules/{id}": {
"put": {
"security": [
{
"SessionCookie": []
}
],
"description": "修改一个定时任务的配置(名称、Cron 表达式、异步任务参数和是否启用等),并触发调度器热加载,需要管理员权限",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "修改定时任务",
"parameters": [
{
"type": "integer",
"description": "定时任务 ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "修改定时任务请求参数",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/task.UpdateScheduleRequest"
}
}
],
"responses": {
"200": {
"description": "修改后的定时任务信息",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.Schedule"
}
}
}
]
}
},
"400": {
"description": "Cron 表达式无效、参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"404": {
"description": "定时任务不存在",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "修改定时任务失败",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
},
"delete": {
"security": [
{
"SessionCookie": []
}
],
"description": "删除指定的定时任务配置,并触发调度器热加载,需要管理员权限",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "删除定时任务",
"parameters": [
{
"type": "integer",
"description": "定时任务 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除结果",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "删除定时任务失败",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/tasks/types": {
"get": {
"security": [
@@ -4362,6 +4643,36 @@ const docTemplate = `{
}
}
},
"model.Schedule": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"cron": {
"type": "string"
},
"id": {
"type": "string",
"example": "0"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"payload": {
"type": "string"
},
"task_type": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"model.SystemConfig": {
"type": "object",
"properties": {
@@ -4933,6 +5244,32 @@ const docTemplate = `{
}
}
},
"task.CreateScheduleRequest": {
"type": "object",
"required": [
"cron",
"is_active",
"name",
"task_type"
],
"properties": {
"cron": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"payload": {
"type": "string"
},
"task_type": {
"type": "string"
}
}
},
"task.DispatchTaskRequest": {
"type": "object",
"required": [
@@ -5021,6 +5358,32 @@ const docTemplate = `{
}
}
},
"task.UpdateScheduleRequest": {
"type": "object",
"required": [
"cron",
"is_active",
"name",
"task_type"
],
"properties": {
"cron": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"name": {
"type": "string"
},
"payload": {
"type": "string"
},
"task_type": {
"type": "string"
}
}
},
"template.CreateTemplateRequest": {
"type": "object",
"required": [