优化结构

This commit is contained in:
Yvan
2026-08-27 19:08:51 +08:00
parent 653414a1da
commit 5052835fcb
11 changed files with 197 additions and 19 deletions
+9
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"kra/internal/biz/system"
"log/slog"
"strconv"
"strings"
"time"
@@ -138,6 +139,14 @@ func (h *Public) InitializeDatabase(engine *gin.Engine) gin.HandlerFunc {
values = append(values, dto.Route{Path: route.Path, Method: route.Method})
}
if err := h.system.InitializeRoutes(c.Request.Context(), &input, values); err != nil {
// Database activation is already committed before the scheduler reload
// runs. GVA reports initialization success in this case as well; do not
// make the UI retry an operation that cannot safely be repeated.
if errors.Is(err, system.ErrTaskRuntimeReload) {
slog.ErrorContext(c.Request.Context(), "数据库初始化完成,但定时任务恢复失败", "mod", "timedTask", "error", err)
Write(c, CodeSuccess, gin.H{}, "自动创建数据库成功")
return
}
Fail(c, "自动创建数据库失败,请查看后台日志,检查后在进行初始化")
return
}
+11
View File
@@ -1,8 +1,11 @@
package handler
import (
"errors"
"kra/internal/biz/system"
"kra/internal/service"
"kra/internal/service/dto"
"log/slog"
"github.com/gin-gonic/gin"
)
@@ -63,6 +66,14 @@ func (h *SystemConfig) Set(c *gin.Context) {
func (h *SystemConfig) Reload(c *gin.Context) {
if err := h.system.ReloadConfig(c.Request.Context()); err != nil {
// Reloading the data/configuration is committed before task schedules are
// rebuilt. Match GVA's successful HTTP contract for this partial-success
// case while leaving the typed error available to internal callers.
if errors.Is(err, system.ErrTaskRuntimeReload) {
slog.ErrorContext(c.Request.Context(), "系统配置重载完成,但定时任务恢复失败", "mod", "timedTask", "error", err)
Write(c, CodeSuccess, gin.H{}, "重载系统成功")
return
}
Fail(c, "重载系统失败:"+err.Error())
return
}