diff --git a/config.example.yaml b/config.example.yaml
index c1db088e..5eca688d 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -93,9 +93,6 @@ log:
max_backups: 10
compress: true
-# ─── Task Scheduler (Cron) ──────────────────────────────────────────────────────
-scheduler:
- cleanup_unused_uploads_task_cron: "0 */2 * * *" # Clean up orphaned upload records
# ─── Async Task Worker ──────────────────────────────────────────────────────────
worker:
diff --git a/docs/docs.go b/docs/docs.go
index 7cd931ee..c3062316 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -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": [
diff --git a/docs/swagger.json b/docs/swagger.json
index 5d37ed68..44f4bccc 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1652,6 +1652,287 @@
}
}
},
+ "/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": [
@@ -4355,6 +4636,36 @@
}
}
},
+ "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": {
@@ -4926,6 +5237,32 @@
}
}
},
+ "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": [
@@ -5014,6 +5351,32 @@
}
}
},
+ "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": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 57f4e7ca..8c318880 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -277,6 +277,26 @@ definitions:
id:
type: integer
type: object
+ model.Schedule:
+ properties:
+ created_at:
+ type: string
+ cron:
+ type: string
+ id:
+ example: "0"
+ type: string
+ is_active:
+ type: boolean
+ name:
+ type: string
+ payload:
+ type: string
+ task_type:
+ type: string
+ updated_at:
+ type: string
+ type: object
model.SystemConfig:
properties:
created_at:
@@ -667,6 +687,24 @@ definitions:
required:
- value
type: object
+ task.CreateScheduleRequest:
+ properties:
+ cron:
+ type: string
+ is_active:
+ type: boolean
+ name:
+ type: string
+ payload:
+ type: string
+ task_type:
+ type: string
+ required:
+ - cron
+ - is_active
+ - name
+ - task_type
+ type: object
task.DispatchTaskRequest:
properties:
end_time:
@@ -727,6 +765,24 @@ definitions:
description: 类型:string, text, number
type: string
type: object
+ task.UpdateScheduleRequest:
+ properties:
+ cron:
+ type: string
+ is_active:
+ type: boolean
+ name:
+ type: string
+ payload:
+ type: string
+ task_type:
+ type: string
+ required:
+ - cron
+ - is_active
+ - name
+ - task_type
+ type: object
template.CreateTemplateRequest:
properties:
content:
@@ -1941,6 +1997,175 @@ paths:
summary: 重试失败任务
tags:
- admin
+ /api/v1/admin/tasks/schedules:
+ get:
+ description: 返回系统所有的定时任务配置列表,包括名称、关联的异步任务类型、Cron 表达式和启用状态,需要管理员权限
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 定时任务列表
+ schema:
+ allOf:
+ - $ref: '#/definitions/util.ResponseAny'
+ - properties:
+ data:
+ items:
+ $ref: '#/definitions/model.Schedule'
+ type: array
+ type: object
+ "401":
+ description: 未登录
+ schema:
+ $ref: '#/definitions/util.ResponseAny'
+ "403":
+ description: 无管理员权限
+ schema:
+ $ref: '#/definitions/util.ResponseAny'
+ security:
+ - SessionCookie: []
+ summary: 获取定时任务列表
+ tags:
+ - admin
+ post:
+ consumes:
+ - application/json
+ description: 新增一个动态定时任务配置,关联已有的异步任务,配置 Cron 表达式和执行参数,并触发调度器热加载,需要管理员权限
+ parameters:
+ - description: 创建定时任务请求参数
+ in: body
+ name: request
+ required: true
+ schema:
+ $ref: '#/definitions/task.CreateScheduleRequest'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 创建成功的定时任务信息
+ schema:
+ allOf:
+ - $ref: '#/definitions/util.ResponseAny'
+ - properties:
+ data:
+ $ref: '#/definitions/model.Schedule'
+ type: object
+ "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'
+ security:
+ - SessionCookie: []
+ summary: 创建定时任务
+ tags:
+ - admin
+ /api/v1/admin/tasks/schedules/{id}:
+ delete:
+ description: 删除指定的定时任务配置,并触发调度器热加载,需要管理员权限
+ parameters:
+ - description: 定时任务 ID
+ in: path
+ name: id
+ required: true
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 删除结果
+ schema:
+ allOf:
+ - $ref: '#/definitions/util.ResponseAny'
+ - properties:
+ data:
+ type: string
+ type: object
+ "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'
+ security:
+ - SessionCookie: []
+ summary: 删除定时任务
+ tags:
+ - admin
+ put:
+ consumes:
+ - application/json
+ description: 修改一个定时任务的配置(名称、Cron 表达式、异步任务参数和是否启用等),并触发调度器热加载,需要管理员权限
+ parameters:
+ - description: 定时任务 ID
+ in: path
+ name: id
+ required: true
+ type: integer
+ - description: 修改定时任务请求参数
+ in: body
+ name: request
+ required: true
+ schema:
+ $ref: '#/definitions/task.UpdateScheduleRequest'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: 修改后的定时任务信息
+ schema:
+ allOf:
+ - $ref: '#/definitions/util.ResponseAny'
+ - properties:
+ data:
+ $ref: '#/definitions/model.Schedule'
+ type: object
+ "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'
+ security:
+ - SessionCookie: []
+ summary: 修改定时任务
+ tags:
+ - admin
/api/v1/admin/tasks/types:
get:
description: 返回系统支持的所有可调度任务类型列表,包括任务名称、描述、是否支持时间范围等元数据,需要管理员权限
diff --git a/frontend/app/(main)/admin/tasks/executions/page.tsx b/frontend/app/(main)/admin/tasks/executions/page.tsx
deleted file mode 100644
index 9bd5f49e..00000000
--- a/frontend/app/(main)/admin/tasks/executions/page.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-"use client"
-
-import {TaskExecutionsManager} from "@/components/common/admin/task-executions"
-
-/* 任务日志页面 */
-export default function TaskExecutionsPage() {
- return