refactor(service): 重构模型网关服务结构

This commit is contained in:
2026-06-11 17:58:49 +08:00
parent afd60caf56
commit 1c6c9bae14
34 changed files with 784 additions and 1223 deletions

29
main.go
View File

@@ -3,7 +3,6 @@ package main
import (
"context"
"model-gateway/model/dto"
"model-gateway/service/job"
"model-gateway/service/task"
"os"
"os/signal"
@@ -27,9 +26,9 @@ func main() {
// 注册路由
http.RouteRegister([]interface{}{
controller.Model,
controller.Task,
controller.Stat,
controller.ModelGatewayModels,
controller.ModelGatewayTask,
controller.ModelGatewayLogsStat,
})
// 本地调试:可选自动触发 worker/cleaner由配置文件控制
@@ -47,26 +46,6 @@ func main() {
}
func startAutoRunner(ctx context.Context) {
// cleaner
if g.Cfg().MustGet(ctx, "asynch.cleaner.enabled").Bool() {
interval := g.Cfg().MustGet(ctx, "asynch.cleaner.intervalSeconds").Int()
if interval <= 0 {
interval = 30
}
ticker := time.NewTicker(time.Duration(interval) * time.Second)
go func() {
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
_, _ = job.Cleaner.RunOnce(ctx)
}
}
}()
}
// queryPending
if g.Cfg().MustGet(ctx, "asynch.queryPending.enabled").Bool() {
interval := g.Cfg().MustGet(ctx, "asynch.queryPending.intervalSeconds", 10).Int()
@@ -79,7 +58,7 @@ func startAutoRunner(ctx context.Context) {
case <-ctx.Done():
return
case <-ticker.C:
if _, err := task.Task.QueryPendingTasks(ctx, &dto.QueryPendingTasksReq{Limit: limit}); err != nil {
if _, err := task.ModelGatewayTask.QueryPendingTasks(ctx, &dto.QueryPendingTasksReq{Limit: limit}); err != nil {
g.Log().Warningf(ctx, "[auto-queryPending] run once failed: %v", err)
}
}