From cf7a0a32bace9d3a397878eb672c1b8b7e61d0d6 Mon Sep 17 00:00:00 2001 From: zhaojianbin Date: Thu, 19 Sep 2024 09:50:56 +0800 Subject: [PATCH 1/2] add cron some issues --- .../app/network/controller/agentcontroller/cron.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/server/app/network/controller/agentcontroller/cron.go b/cmd/server/app/network/controller/agentcontroller/cron.go index 6001607e..69acd9d7 100644 --- a/cmd/server/app/network/controller/agentcontroller/cron.go +++ b/cmd/server/app/network/controller/agentcontroller/cron.go @@ -25,6 +25,7 @@ import ( "github.com/gin-gonic/gin" ) +// CreatCron 创建定时任务 func CreatCron(c *gin.Context) { // 存入数据库 var newCron cron.CrontabUpdate @@ -91,6 +92,7 @@ func CreatCron(c *gin.Context) { response.Success(c, gin.H{"data": newCron, "cron": cron_start}, "任务已生效") } +// DeleteCronTask 是一个删除定时任务的函数 func DeleteCronTask(c *gin.Context) { var crons cron.DelCrons var cronIds string @@ -114,6 +116,7 @@ func DeleteCronTask(c *gin.Context) { response.Success(c, nil, "任务删除成功!") } +// UpdateCron 是一个处理更新定时任务的函数 func UpdateCron(c *gin.Context) { var Cron cron.CrontabUpdate c.Bind(&Cron) @@ -157,6 +160,7 @@ func UpdateCron(c *gin.Context) { response.Success(c, gin.H{"cron": cron_start}, "任务更新成功,已开始执行") } +// CronTaskStatus 处理任务状态更新请求 func CronTaskStatus(c *gin.Context) { var Cron cron.CrontabUpdate c.Bind(&Cron) @@ -201,6 +205,7 @@ func CronTaskStatus(c *gin.Context) { response.Success(c, gin.H{"cron": cron_start}, "任务已开启") } +// CronTaskList 获取定时任务列表 func CronTaskList(c *gin.Context) { uuid := c.Query("uuid") @@ -211,8 +216,8 @@ func CronTaskList(c *gin.Context) { return } - num := query.Size * (query.CurrentPageNum - 1) - total, data, err := cron.CronListPaged(uuid, num, query.Size) + offset := query.Size * (query.CurrentPageNum - 1) + total, data, err := cron.CronListPaged(uuid, offset, query.Size) if err != nil { response.Fail(c, gin.H{"status": false}, err.Error()) return -- Gitee From b17cf89de19b82859ca4a21c5d35aee744d089bd Mon Sep 17 00:00:00 2001 From: zhaojianbin Date: Thu, 19 Sep 2024 10:51:11 +0800 Subject: [PATCH 2/2] fix uuid empty bugs --- .../app/network/controller/agentcontroller/config.go | 4 ++++ cmd/server/app/network/controller/agentcontroller/cpu.go | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/server/app/network/controller/agentcontroller/config.go b/cmd/server/app/network/controller/agentcontroller/config.go index f10468f6..3e6bda84 100644 --- a/cmd/server/app/network/controller/agentcontroller/config.go +++ b/cmd/server/app/network/controller/agentcontroller/config.go @@ -9,6 +9,10 @@ import ( func ConfigfileHandler(c *gin.Context) { uuid := c.Query("uuid") + if uuid == "" { + response.Fail(c, nil, "uuid参数缺失") + return + } agent := agentmanager.GetAgent(uuid) if agent == nil { response.Fail(c, nil, "获取uuid失败!") diff --git a/cmd/server/app/network/controller/agentcontroller/cpu.go b/cmd/server/app/network/controller/agentcontroller/cpu.go index d2243967..87bcd90d 100644 --- a/cmd/server/app/network/controller/agentcontroller/cpu.go +++ b/cmd/server/app/network/controller/agentcontroller/cpu.go @@ -22,17 +22,20 @@ import ( func CPUInfoHandler(c *gin.Context) { uuid := c.Query("uuid") - + if uuid == "" { + response.Fail(c, nil, "uuid参数缺失") + return + } agent := agentmanager.GetAgent(uuid) if agent == nil { response.Fail(c, nil, "获取uuid失败!") return } - cpu_info, err := agent.GetCPUInfo() + cpuInfo, err := agent.GetCPUInfo() if err != nil { response.Fail(c, nil, "获取系统CPU信息失败!") return } - response.Success(c, gin.H{"CPU_info": cpu_info}, "Success") + response.Success(c, gin.H{"CPU_info": cpuInfo}, "Success") } -- Gitee