fix: agent exec log error

This commit is contained in:
engigu
2026-01-03 12:36:41 +08:00
parent 69da61b9a0
commit 6ffb65eebe
11 changed files with 103 additions and 43 deletions
+22 -6
View File
@@ -7,18 +7,18 @@ import (
"baihu/internal/constant"
"baihu/internal/database"
"baihu/internal/models"
"baihu/internal/services"
"baihu/internal/services/tasks"
"baihu/internal/utils"
"github.com/gin-gonic/gin"
)
type DashboardController struct {
cronService *services.CronService
executorService *services.ExecutorService
cronService *tasks.CronService
executorService *tasks.ExecutorService
}
func NewDashboardController(cronService *services.CronService, executorService *services.ExecutorService) *DashboardController {
func NewDashboardController(cronService *tasks.CronService, executorService *tasks.ExecutorService) *DashboardController {
return &DashboardController{
cronService: cronService,
executorService: executorService,
@@ -45,13 +45,29 @@ func (dc *DashboardController) GetStats(c *gin.Context) {
today := time.Now().Format("2006-01-02")
database.DB.Model(&models.SendStats{}).Where("day = ?", today).Select("COALESCE(SUM(num), 0)").Scan(&todayExecs)
// 调度统计:本地调度 + Agent 调度
// 本地调度:agent_id 为 NULL 且 enabled = true 的任务
localScheduled := dc.cronService.GetScheduledCount()
// Agent 调度:agent_id 不为 NULL 且 enabled = true 的任务
var agentScheduled int64
database.DB.Model(&models.Task{}).
Where("agent_id IS NOT NULL AND enabled = ?", true).
Count(&agentScheduled)
totalScheduled := localScheduled + int(agentScheduled)
// 正在运行:目前只能统计本地运行的任务
// Agent 端的运行状态需要通过心跳上报(未来优化)
running := dc.executorService.GetRunningCount()
stats := StatsResponse{
Tasks: taskCount,
TodayExecs: todayExecs,
Envs: envCount,
Logs: logCount,
Scheduled: dc.cronService.GetScheduledCount(),
Running: dc.executorService.GetRunningCount(),
Scheduled: totalScheduled,
Running: running,
}
utils.Success(c, stats)
+3 -3
View File
@@ -3,17 +3,17 @@ package controllers
import (
"strconv"
"baihu/internal/services"
"baihu/internal/services/tasks"
"baihu/internal/utils"
"github.com/gin-gonic/gin"
)
type ExecutorController struct {
executorService *services.ExecutorService
executorService *tasks.ExecutorService
}
func NewExecutorController(executorService *services.ExecutorService) *ExecutorController {
func NewExecutorController(executorService *tasks.ExecutorService) *ExecutorController {
return &ExecutorController{executorService: executorService}
}
+3 -2
View File
@@ -9,6 +9,7 @@ import (
"baihu/internal/database"
"baihu/internal/models"
"baihu/internal/services"
"baihu/internal/services/tasks"
"baihu/internal/utils"
"fmt"
"os"
@@ -23,10 +24,10 @@ type SettingsController struct {
settingsService *services.SettingsService
loginLogService *services.LoginLogService
backupService *services.BackupService
executorService *services.ExecutorService
executorService *tasks.ExecutorService
}
func NewSettingsController(userService *services.UserService, loginLogService *services.LoginLogService, executorService *services.ExecutorService) *SettingsController {
func NewSettingsController(userService *services.UserService, loginLogService *services.LoginLogService, executorService *tasks.ExecutorService) *SettingsController {
return &SettingsController{
userService: userService,
settingsService: services.NewSettingsService(),
+4 -3
View File
@@ -6,18 +6,19 @@ import (
"baihu/internal/constant"
"baihu/internal/services"
"baihu/internal/services/tasks"
"baihu/internal/utils"
"github.com/gin-gonic/gin"
)
type TaskController struct {
taskService *services.TaskService
cronService *services.CronService
taskService *tasks.TaskService
cronService *tasks.CronService
agentWSManager *services.AgentWSManager
}
func NewTaskController(taskService *services.TaskService, cronService *services.CronService) *TaskController {
func NewTaskController(taskService *tasks.TaskService, cronService *tasks.CronService) *TaskController {
return &TaskController{
taskService: taskService,
cronService: cronService,