chore: trt to fix restore bool val #70
This commit is contained in:
@@ -72,7 +72,7 @@ func (c *AgentController) Update(ctx *gin.Context) {
|
|||||||
utils.NotFound(ctx, "Agent 不存在")
|
utils.NotFound(ctx, "Agent 不存在")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wasEnabled := oldAgent.Enabled
|
wasEnabled := utils.DerefBool(oldAgent.Enabled, true)
|
||||||
|
|
||||||
if err := c.agentService.Update(id, req.Name, req.Description, req.Enabled); err != nil {
|
if err := c.agentService.Update(id, req.Name, req.Description, req.Enabled); err != nil {
|
||||||
utils.ServerError(ctx, err.Error())
|
utils.ServerError(ctx, err.Error())
|
||||||
@@ -233,7 +233,7 @@ func (c *AgentController) GetTasks(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !agent.Enabled {
|
if !utils.DerefBool(agent.Enabled, true) {
|
||||||
utils.Forbidden(ctx, "Agent 已禁用")
|
utils.Forbidden(ctx, "Agent 已禁用")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,7 @@ func (c *AgentController) ReportResult(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !agent.Enabled {
|
if !utils.DerefBool(agent.Enabled, true) {
|
||||||
utils.Forbidden(ctx, "Agent 已禁用")
|
utils.Forbidden(ctx, "Agent 已禁用")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -393,7 +393,7 @@ func (c *AgentController) WSConnect(ctx *gin.Context) {
|
|||||||
logger.Infof("[AgentWS] 注册成功: Agent #%s, isNew=%v", agent.ID, isNewAgent)
|
logger.Infof("[AgentWS] 注册成功: Agent #%s, isNew=%v", agent.ID, isNewAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !agent.Enabled {
|
if !utils.DerefBool(agent.Enabled, true) {
|
||||||
c.wsManager.RecordConnectFail(ip)
|
c.wsManager.RecordConnectFail(ip)
|
||||||
logger.Warnf("[AgentWS] Agent #%s 已禁用, IP=%s", agent.ID, ip)
|
logger.Warnf("[AgentWS] Agent #%s 已禁用, IP=%s", agent.ID, ip)
|
||||||
ctx.JSON(http.StatusForbidden, gin.H{"error": "Agent 已禁用"})
|
ctx.JSON(http.StatusForbidden, gin.H{"error": "Agent 已禁用"})
|
||||||
|
|||||||
@@ -183,15 +183,15 @@ func (ec *EnvController) UpdateEnvVar(c *gin.Context) {
|
|||||||
|
|
||||||
hidden := existing.Hidden
|
hidden := existing.Hidden
|
||||||
if req.Hidden != nil {
|
if req.Hidden != nil {
|
||||||
hidden = *req.Hidden
|
hidden = req.Hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled := existing.Enabled
|
enabled := existing.Enabled
|
||||||
if req.Enabled != nil {
|
if req.Enabled != nil {
|
||||||
enabled = *req.Enabled
|
enabled = req.Enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
envVar := ec.envService.UpdateEnvVar(id, req.Name, req.Value, req.Remark, req.Type, hidden, enabled)
|
envVar := ec.envService.UpdateEnvVar(id, req.Name, req.Value, req.Remark, req.Type, utils.DerefBool(hidden, true), utils.DerefBool(enabled, true))
|
||||||
if envVar == nil {
|
if envVar == nil {
|
||||||
utils.NotFound(c, "环境变量不存在")
|
utils.NotFound(c, "环境变量不存在")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ func (tc *TaskController) UpdateTask(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 本地任务
|
// 本地任务
|
||||||
if task.Enabled {
|
if utils.DerefBool(task.Enabled, true) {
|
||||||
tc.executorService.AddCronTask(task)
|
tc.executorService.AddCronTask(task)
|
||||||
} else {
|
} else {
|
||||||
tc.executorService.RemoveCronTask(task.ID)
|
tc.executorService.RemoveCronTask(task.ID)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type Agent struct {
|
|||||||
OS string `json:"os" gorm:"size:20"` // 操作系统
|
OS string `json:"os" gorm:"size:20"` // 操作系统
|
||||||
Arch string `json:"arch" gorm:"size:20"` // 架构
|
Arch string `json:"arch" gorm:"size:20"` // 架构
|
||||||
ForceUpdate bool `json:"force_update" gorm:"default:false"` // 强制更新标志
|
ForceUpdate bool `json:"force_update" gorm:"default:false"` // 强制更新标志
|
||||||
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
|
Enabled *bool `json:"enabled" gorm:"default:true"` // 是否启用
|
||||||
CreatedAt LocalTime `json:"created_at"`
|
CreatedAt LocalTime `json:"created_at"`
|
||||||
UpdatedAt LocalTime `json:"updated_at"`
|
UpdatedAt LocalTime `json:"updated_at"`
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ type AgentToken struct {
|
|||||||
MaxUses int `json:"max_uses" gorm:"default:0"` // 最大使用次数,0 表示无限制
|
MaxUses int `json:"max_uses" gorm:"default:0"` // 最大使用次数,0 表示无限制
|
||||||
UsedCount int `json:"used_count" gorm:"default:0"` // 已使用次数
|
UsedCount int `json:"used_count" gorm:"default:0"` // 已使用次数
|
||||||
ExpiresAt *LocalTime `json:"expires_at"` // 过期时间,null 表示永不过期
|
ExpiresAt *LocalTime `json:"expires_at"` // 过期时间,null 表示永不过期
|
||||||
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
|
Enabled *bool `json:"enabled" gorm:"default:true"` // 是否启用
|
||||||
CreatedAt LocalTime `json:"created_at"`
|
CreatedAt LocalTime `json:"created_at"`
|
||||||
UpdatedAt LocalTime `json:"updated_at"`
|
UpdatedAt LocalTime `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ type EnvironmentVariable struct {
|
|||||||
Value BigText `json:"value"`
|
Value BigText `json:"value"`
|
||||||
Remark string `json:"remark" gorm:"size:500"`
|
Remark string `json:"remark" gorm:"size:500"`
|
||||||
Type string `json:"type" gorm:"size:20;default:'normal'"`
|
Type string `json:"type" gorm:"size:20;default:'normal'"`
|
||||||
Hidden bool `json:"hidden" gorm:"default:true"`
|
Hidden *bool `json:"hidden" gorm:"default:true"`
|
||||||
Enabled bool `json:"enabled" gorm:"default:true"`
|
Enabled *bool `json:"enabled" gorm:"default:true"`
|
||||||
UserID string `json:"user_id" gorm:"size:20;index"`
|
UserID string `json:"user_id" gorm:"size:20;index"`
|
||||||
CreatedAt LocalTime `json:"created_at"`
|
CreatedAt LocalTime `json:"created_at"`
|
||||||
UpdatedAt LocalTime `json:"updated_at"`
|
UpdatedAt LocalTime `json:"updated_at"`
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type NotifyWay struct {
|
|||||||
Name string `json:"name" gorm:"size:100;not null"`
|
Name string `json:"name" gorm:"size:100;not null"`
|
||||||
Type string `json:"type" gorm:"size:50;not null;index"`
|
Type string `json:"type" gorm:"size:50;not null;index"`
|
||||||
Config BigText `json:"config"`
|
Config BigText `json:"config"`
|
||||||
Enabled bool `json:"enabled" gorm:"default:true;index"`
|
Enabled *bool `json:"enabled" gorm:"default:true;index"`
|
||||||
CreatedAt LocalTime `json:"created_at"`
|
CreatedAt LocalTime `json:"created_at"`
|
||||||
UpdatedAt LocalTime `json:"updated_at"`
|
UpdatedAt LocalTime `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ type Task struct {
|
|||||||
RetryCount int `json:"retry_count" gorm:"default:0"` // 失败重试次数
|
RetryCount int `json:"retry_count" gorm:"default:0"` // 失败重试次数
|
||||||
RetryInterval int `json:"retry_interval" gorm:"default:0"` // 失败重试间隔(秒)
|
RetryInterval int `json:"retry_interval" gorm:"default:0"` // 失败重试间隔(秒)
|
||||||
RandomRange int `json:"random_range" gorm:"default:0"` // 随机延迟范围(秒)
|
RandomRange int `json:"random_range" gorm:"default:0"` // 随机延迟范围(秒)
|
||||||
Enabled bool `json:"enabled" gorm:"default:true"`
|
Enabled *bool `json:"enabled" gorm:"default:true"`
|
||||||
RunningGo BigText `json:"running_go"` // 正在运行的 go routine id 数组 (JSON)
|
RunningGo BigText `json:"running_go"` // 正在运行的 go routine id 数组 (JSON)
|
||||||
RuntimeEnvs []string `json:"-" gorm:"-"` // 运行时环境变量(非持久化)
|
RuntimeEnvs []string `json:"-" gorm:"-"` // 运行时环境变量(非持久化)
|
||||||
RuntimeSecrets []string `json:"-" gorm:"-"` // 运行时安全机密(非持久化)
|
RuntimeSecrets []string `json:"-" gorm:"-"` // 运行时安全机密(非持久化)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package vo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/engigu/baihu-panel/internal/models"
|
"github.com/engigu/baihu-panel/internal/models"
|
||||||
|
"github.com/engigu/baihu-panel/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AgentVO 代理视图对象
|
// AgentVO 代理视图对象
|
||||||
@@ -42,7 +43,7 @@ func ToAgentVO(agent *models.Agent) *AgentVO {
|
|||||||
OS: agent.OS,
|
OS: agent.OS,
|
||||||
Arch: agent.Arch,
|
Arch: agent.Arch,
|
||||||
ForceUpdate: agent.ForceUpdate,
|
ForceUpdate: agent.ForceUpdate,
|
||||||
Enabled: agent.Enabled,
|
Enabled: utils.DerefBool(agent.Enabled, true),
|
||||||
CreatedAt: agent.CreatedAt,
|
CreatedAt: agent.CreatedAt,
|
||||||
UpdatedAt: agent.UpdatedAt,
|
UpdatedAt: agent.UpdatedAt,
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,7 @@ func ToAgentTokenVO(token *models.AgentToken) *AgentTokenVO {
|
|||||||
MaxUses: token.MaxUses,
|
MaxUses: token.MaxUses,
|
||||||
UsedCount: token.UsedCount,
|
UsedCount: token.UsedCount,
|
||||||
ExpiresAt: token.ExpiresAt,
|
ExpiresAt: token.ExpiresAt,
|
||||||
Enabled: token.Enabled,
|
Enabled: utils.DerefBool(token.Enabled, true),
|
||||||
CreatedAt: token.CreatedAt,
|
CreatedAt: token.CreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package vo
|
|||||||
import (
|
import (
|
||||||
"github.com/engigu/baihu-panel/internal/constant"
|
"github.com/engigu/baihu-panel/internal/constant"
|
||||||
"github.com/engigu/baihu-panel/internal/models"
|
"github.com/engigu/baihu-panel/internal/models"
|
||||||
|
"github.com/engigu/baihu-panel/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserVO 用户视图对象
|
// UserVO 用户视图对象
|
||||||
@@ -58,8 +59,8 @@ func ToEnvVO(env *models.EnvironmentVariable) *EnvVO {
|
|||||||
Value: val,
|
Value: val,
|
||||||
Remark: env.Remark,
|
Remark: env.Remark,
|
||||||
Type: env.Type,
|
Type: env.Type,
|
||||||
Hidden: env.Hidden,
|
Hidden: utils.DerefBool(env.Hidden, true),
|
||||||
Enabled: env.Enabled,
|
Enabled: utils.DerefBool(env.Enabled, true),
|
||||||
CreatedAt: env.CreatedAt,
|
CreatedAt: env.CreatedAt,
|
||||||
UpdatedAt: env.UpdatedAt,
|
UpdatedAt: env.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package vo
|
|||||||
import (
|
import (
|
||||||
"github.com/engigu/baihu-panel/internal/executor"
|
"github.com/engigu/baihu-panel/internal/executor"
|
||||||
"github.com/engigu/baihu-panel/internal/models"
|
"github.com/engigu/baihu-panel/internal/models"
|
||||||
|
"github.com/engigu/baihu-panel/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskVO 任务视图对象
|
// TaskVO 任务视图对象
|
||||||
@@ -53,7 +54,7 @@ func ToTaskVO(task *models.Task) *TaskVO {
|
|||||||
Languages: task.Languages,
|
Languages: task.Languages,
|
||||||
AgentID: task.AgentID,
|
AgentID: task.AgentID,
|
||||||
RepoTaskID: task.RepoTaskID,
|
RepoTaskID: task.RepoTaskID,
|
||||||
Enabled: task.Enabled,
|
Enabled: utils.DerefBool(task.Enabled, true),
|
||||||
RetryCount: task.RetryCount,
|
RetryCount: task.RetryCount,
|
||||||
RetryInterval: task.RetryInterval,
|
RetryInterval: task.RetryInterval,
|
||||||
RandomRange: task.RandomRange,
|
RandomRange: task.RandomRange,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func (s *AgentService) CreateToken(remark string, maxUses int, expiresAt *time.T
|
|||||||
Remark: remark,
|
Remark: remark,
|
||||||
MaxUses: maxUses,
|
MaxUses: maxUses,
|
||||||
ExpiresAt: expires,
|
ExpiresAt: expires,
|
||||||
Enabled: true,
|
Enabled: utils.BoolPtr(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.DB.Create(agentToken).Error; err != nil {
|
if err := database.DB.Create(agentToken).Error; err != nil {
|
||||||
@@ -85,7 +85,7 @@ func (s *AgentService) ValidateToken(token string) (*models.AgentToken, error) {
|
|||||||
return nil, &ServiceError{Message: "无效的令牌"}
|
return nil, &ServiceError{Message: "无效的令牌"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !agentToken.Enabled {
|
if !utils.DerefBool(agentToken.Enabled, true) {
|
||||||
return nil, &ServiceError{Message: "令牌已禁用"}
|
return nil, &ServiceError{Message: "令牌已禁用"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ func (s *AgentService) RegisterByToken(token string, machineID string, ip string
|
|||||||
IP: ip,
|
IP: ip,
|
||||||
Status: constant.AgentStatusOnline,
|
Status: constant.AgentStatusOnline,
|
||||||
LastSeen: &now,
|
LastSeen: &now,
|
||||||
Enabled: true,
|
Enabled: utils.BoolPtr(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.DB.Create(agent).Error; err != nil {
|
if err := database.DB.Create(agent).Error; err != nil {
|
||||||
@@ -190,7 +190,7 @@ func (s *AgentService) Register(req *models.AgentRegisterRequest, ip string) (*m
|
|||||||
IP: ip,
|
IP: ip,
|
||||||
Status: constant.AgentStatusOnline,
|
Status: constant.AgentStatusOnline,
|
||||||
LastSeen: &now,
|
LastSeen: &now,
|
||||||
Enabled: true,
|
Enabled: utils.BoolPtr(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.DB.Create(agent).Error; err != nil {
|
if err := database.DB.Create(agent).Error; err != nil {
|
||||||
@@ -207,7 +207,7 @@ func (s *AgentService) Update(id string, name, description string, enabled bool)
|
|||||||
return database.DB.Model(&models.Agent{}).Where("id = ?", id).Updates(map[string]interface{}{
|
return database.DB.Model(&models.Agent{}).Where("id = ?", id).Updates(map[string]interface{}{
|
||||||
"name": name,
|
"name": name,
|
||||||
"description": description,
|
"description": description,
|
||||||
"enabled": enabled,
|
"enabled": &enabled,
|
||||||
}).Error
|
}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ func (s *AgentService) Heartbeat(token, ip, version, buildTime, hostname, osType
|
|||||||
return nil, &ServiceError{Message: "无效的 Token"}
|
return nil, &ServiceError{Message: "无效的 Token"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !agent.Enabled {
|
if !utils.DerefBool(agent.Enabled, true) {
|
||||||
return nil, &ServiceError{Message: "Agent 已禁用"}
|
return nil, &ServiceError{Message: "Agent 已禁用"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ func (s *AgentService) GetTasks(agentID string) []models.AgentTask {
|
|||||||
Languages: []map[string]string(task.Languages),
|
Languages: []map[string]string(task.Languages),
|
||||||
RandomRange: task.RandomRange,
|
RandomRange: task.RandomRange,
|
||||||
Secrets: secrets,
|
Secrets: secrets,
|
||||||
Enabled: task.Enabled,
|
Enabled: utils.DerefBool(task.Enabled, true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ func (es *EnvService) CreateEnvVar(name, value, remark, envType string, hidden,
|
|||||||
Value: models.BigText(value),
|
Value: models.BigText(value),
|
||||||
Remark: remark,
|
Remark: remark,
|
||||||
Type: envType,
|
Type: envType,
|
||||||
Hidden: hidden,
|
Hidden: &hidden,
|
||||||
Enabled: enabled,
|
Enabled: &enabled,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
CreatedAt: models.Now(),
|
CreatedAt: models.Now(),
|
||||||
UpdatedAt: models.Now(),
|
UpdatedAt: models.Now(),
|
||||||
@@ -99,8 +99,8 @@ func (es *EnvService) UpdateEnvVar(id string, name, value, remark, envType strin
|
|||||||
"value": models.BigText(value),
|
"value": models.BigText(value),
|
||||||
"remark": remark,
|
"remark": remark,
|
||||||
"type": envType,
|
"type": envType,
|
||||||
"hidden": hidden,
|
"hidden": &hidden,
|
||||||
"enabled": enabled,
|
"enabled": &enabled,
|
||||||
}
|
}
|
||||||
database.DB.Model(&env).Updates(updates)
|
database.DB.Model(&env).Updates(updates)
|
||||||
return &env
|
return &env
|
||||||
@@ -224,7 +224,7 @@ func (es *EnvService) formatEnvVars(envs []models.EnvironmentVariable) []string
|
|||||||
}
|
}
|
||||||
|
|
||||||
value := string(env.Value)
|
value := string(env.Value)
|
||||||
if !env.Enabled {
|
if !utils.DerefBool(env.Enabled, true) {
|
||||||
value = ""
|
value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,13 +266,13 @@ func (es *EnvService) formatEnvVarsAndSecrets(envs []models.EnvironmentVariable)
|
|||||||
if env.Type == constant.EnvTypeSecret {
|
if env.Type == constant.EnvTypeSecret {
|
||||||
if decValue, err := utils.Decrypt(value); err == nil {
|
if decValue, err := utils.Decrypt(value); err == nil {
|
||||||
value = decValue
|
value = decValue
|
||||||
if env.Enabled && value != "" {
|
if utils.DerefBool(env.Enabled, true) && value != "" {
|
||||||
secrets = append(secrets, value)
|
secrets = append(secrets, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !env.Enabled {
|
if !utils.DerefBool(env.Enabled, true) {
|
||||||
value = ""
|
value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (s *NotificationService) SaveChannel(channel NotifyChannel) error {
|
|||||||
Name: channel.Name,
|
Name: channel.Name,
|
||||||
Type: channel.Type,
|
Type: channel.Type,
|
||||||
Config: models.BigText(configJSON),
|
Config: models.BigText(configJSON),
|
||||||
Enabled: channel.Enabled,
|
Enabled: utils.BoolPtr(channel.Enabled),
|
||||||
}
|
}
|
||||||
return database.DB.Create(notifyWay).Error
|
return database.DB.Create(notifyWay).Error
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func (s *NotificationService) SaveChannel(channel NotifyChannel) error {
|
|||||||
"name": channel.Name,
|
"name": channel.Name,
|
||||||
"type": channel.Type,
|
"type": channel.Type,
|
||||||
"config": models.BigText(configJSON),
|
"config": models.BigText(configJSON),
|
||||||
"enabled": channel.Enabled,
|
"enabled": &channel.Enabled,
|
||||||
}
|
}
|
||||||
return database.DB.Model(&models.NotifyWay{}).Where("id = ?", channel.ID).Updates(updates).Error
|
return database.DB.Model(&models.NotifyWay{}).Where("id = ?", channel.ID).Updates(updates).Error
|
||||||
}
|
}
|
||||||
@@ -282,7 +282,7 @@ func (s *NotificationService) SendByChannelID(channelID string, msg *NotifyMessa
|
|||||||
return &NotifyResult{Success: false, Error: "渠道不存在"}
|
return &NotifyResult{Success: false, Error: "渠道不存在"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !notifyWay.Enabled {
|
if !utils.DerefBool(notifyWay.Enabled, true) {
|
||||||
return &NotifyResult{Success: false, Error: "渠道已禁用"}
|
return &NotifyResult{Success: false, Error: "渠道已禁用"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ func (s *NotificationService) SendByChannelID(channelID string, msg *NotifyMessa
|
|||||||
ID: notifyWay.ID,
|
ID: notifyWay.ID,
|
||||||
Name: notifyWay.Name,
|
Name: notifyWay.Name,
|
||||||
Type: notifyWay.Type,
|
Type: notifyWay.Type,
|
||||||
Enabled: notifyWay.Enabled,
|
Enabled: utils.DerefBool(notifyWay.Enabled, true),
|
||||||
Config: config,
|
Config: config,
|
||||||
}
|
}
|
||||||
return s.SendToChannel(ch, msg)
|
return s.SendToChannel(ch, msg)
|
||||||
@@ -533,7 +533,7 @@ func (s *NotificationService) getChannelsInternal() []NotifyChannel {
|
|||||||
ID: nw.ID,
|
ID: nw.ID,
|
||||||
Name: nw.Name,
|
Name: nw.Name,
|
||||||
Type: nw.Type,
|
Type: nw.Type,
|
||||||
Enabled: nw.Enabled,
|
Enabled: utils.DerefBool(nw.Enabled, true),
|
||||||
CreatedAt: nw.CreatedAt,
|
CreatedAt: nw.CreatedAt,
|
||||||
Config: config,
|
Config: config,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ func (es *ExecutorService) HandleTaskRetry(task *models.Task, req *executor.Exec
|
|||||||
|
|
||||||
es.scheduler.EnqueueDelayed(time.Duration(task.RetryInterval)*time.Second, func() *executor.ExecutionRequest {
|
es.scheduler.EnqueueDelayed(time.Duration(task.RetryInterval)*time.Second, func() *executor.ExecutionRequest {
|
||||||
latestTask := es.taskService.GetTaskByID(task.ID)
|
latestTask := es.taskService.GetTaskByID(task.ID)
|
||||||
if latestTask == nil || !latestTask.Enabled {
|
if latestTask == nil || !utils.DerefBool(latestTask.Enabled, true) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ func (es *ExecutorService) loadCronTasks() {
|
|||||||
tasks := es.taskService.GetTasks()
|
tasks := es.taskService.GetTasks()
|
||||||
count := 0
|
count := 0
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if !task.Enabled {
|
if !utils.DerefBool(task.Enabled, true) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,7 +875,7 @@ func (es *ExecutorService) ExecuteRemoteForScheduler(task *models.Task, logID st
|
|||||||
if res.Error != nil || res.RowsAffected == 0 {
|
if res.Error != nil || res.RowsAffected == 0 {
|
||||||
return nil, fmt.Errorf("Agent #%s 不存在", agentID)
|
return nil, fmt.Errorf("Agent #%s 不存在", agentID)
|
||||||
}
|
}
|
||||||
if !agent.Enabled {
|
if !utils.DerefBool(agent.Enabled, true) {
|
||||||
return nil, fmt.Errorf("Agent #%s 已禁用", agentID)
|
return nil, fmt.Errorf("Agent #%s 已禁用", agentID)
|
||||||
}
|
}
|
||||||
if es.agentWSManager == nil {
|
if es.agentWSManager == nil {
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ func ParseRepoScriptsAndAddCron(es *ExecutorService, taskID string, logWriter io
|
|||||||
}
|
}
|
||||||
database.DB.Save(&existing)
|
database.DB.Save(&existing)
|
||||||
|
|
||||||
if existing.Enabled && es != nil {
|
if utils.DerefBool(existing.Enabled, true) && es != nil {
|
||||||
es.AddCronTask(&existing)
|
es.AddCronTask(&existing)
|
||||||
}
|
}
|
||||||
log("[更新] 任务: %s (%s)", taskName, filename)
|
log("[更新] 任务: %s (%s)", taskName, filename)
|
||||||
@@ -329,7 +329,7 @@ func ParseRepoScriptsAndAddCron(es *ExecutorService, taskID string, logWriter io
|
|||||||
Languages: repoTask.Languages,
|
Languages: repoTask.Languages,
|
||||||
Timeout: repoTask.Timeout,
|
Timeout: repoTask.Timeout,
|
||||||
Config: models.BigText(defaultTaskConfig),
|
Config: models.BigText(defaultTaskConfig),
|
||||||
Enabled: true,
|
Enabled: utils.BoolPtr(true),
|
||||||
WorkDir: displayWorkDir,
|
WorkDir: displayWorkDir,
|
||||||
SourceID: sourceID,
|
SourceID: sourceID,
|
||||||
RepoTaskID: repoTask.ID,
|
RepoTaskID: repoTask.ID,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (ts *TaskService) CreateTask(name, command, schedule string, timeout int, w
|
|||||||
Envs: models.BigText(envs),
|
Envs: models.BigText(envs),
|
||||||
Languages: languages,
|
Languages: languages,
|
||||||
AgentID: agentID,
|
AgentID: agentID,
|
||||||
Enabled: true,
|
Enabled: utils.BoolPtr(true),
|
||||||
RetryCount: retryCount,
|
RetryCount: retryCount,
|
||||||
RetryInterval: retryInterval,
|
RetryInterval: retryInterval,
|
||||||
RandomRange: randomRange,
|
RandomRange: randomRange,
|
||||||
@@ -113,7 +113,7 @@ func (ts *TaskService) UpdateTask(id string, name, command, schedule string, tim
|
|||||||
task.WorkDir = workDir
|
task.WorkDir = workDir
|
||||||
task.CleanConfig = cleanConfig
|
task.CleanConfig = cleanConfig
|
||||||
task.Envs = models.BigText(envs)
|
task.Envs = models.BigText(envs)
|
||||||
task.Enabled = enabled
|
task.Enabled = &enabled
|
||||||
task.AgentID = agentID
|
task.AgentID = agentID
|
||||||
task.Languages = languages
|
task.Languages = languages
|
||||||
task.Config = models.BigText(config)
|
task.Config = models.BigText(config)
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
// BoolPtr returns a pointer to the bool value
|
||||||
|
func BoolPtr(b bool) *bool {
|
||||||
|
return &b
|
||||||
|
}
|
||||||
|
|
||||||
|
// DerefBool returns the value of the bool pointer or default if nil
|
||||||
|
func DerefBool(b *bool, defaultVal bool) bool {
|
||||||
|
if b == nil {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
return *b
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user