Files
model-asynch/main.go
WangLiZhao 4e6b98b7d3 feat(stat): 添加模型请求按天统计功能
- 新增统计控制器、服务层与数据访问层,提供按天统计接口
- 在 worker 处理任务时原子累加请求计数(仅实际调用模型时计数)
- 更新数据库表结构,添加 asynch_model_stat 表及索引
- 更新文档说明统计功能的使用方式与统计口径
2026-04-27 10:42:42 +08:00

57 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"context"
"os"
"os/signal"
"syscall"
"model-asynch/controller"
"model-asynch/service"
_ "gitea.com/red-future/common/config"
"gitea.com/red-future/common/http"
"gitea.com/red-future/common/jaeger"
_ "gitea.com/red-future/common/swagger"
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
defer jaeger.ShutDown(ctx)
// 注册路由
http.RouteRegister([]interface{}{
controller.Model,
controller.Task,
controller.Stat,
})
// 启动后台任务worker + 清理器
if g.Cfg().MustGet(ctx, "asynch.worker.enabled", true).Bool() {
service.AsyncWorker.Start(ctx) // 启动 worker 协程池
} else {
g.Log().Warningf(ctx, "[main] asynch.worker.enabled=false跳过启动 worker")
}
if g.Cfg().MustGet(ctx, "asynch.cleaner.enabled", true).Bool() {
service.Cleaner.Start(ctx) // 启动清理器
} else {
g.Log().Warningf(ctx, "[main] asynch.cleaner.enabled=false跳过启动 cleaner")
}
// 监听退出信号,确保 Ctrl+C 能完整退出(停止 worker/cleaner 并关闭 http server
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit
g.Log().Infof(ctx, "[main] 收到退出信号,开始优雅退出...")
cancel()
// 停止 worker关闭协程池
service.AsyncWorker.Stop(ctx)
// 关闭 http serverRouteRegister 内部是 go Httpserver.Run() 启动的)
_ = http.Httpserver.Shutdown()
}