diff --git a/internal/app/model/process.go b/internal/app/model/process.go index 7007e54..5c7deb7 100644 --- a/internal/app/model/process.go +++ b/internal/app/model/process.go @@ -9,7 +9,7 @@ type Process struct { Cwd string `gorm:"column:cwd" json:"cwd"` AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"` CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"` - Push bool `gorm:"column:push" json:"push"` + PushIds string `gorm:"column:push_ids" json:"pushIds"` LogReport bool `gorm:"column:log_report" json:"logReport"` TermType constants.TerminalType `gorm:"column:term_type" json:"termType"` CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"` diff --git a/internal/app/service/process.go b/internal/app/service/process.go index 380c5f1..2996f72 100644 --- a/internal/app/service/process.go +++ b/internal/app/service/process.go @@ -14,6 +14,7 @@ import ( "github.com/lzh-1625/go_process_manager/internal/app/middle" "github.com/lzh-1625/go_process_manager/internal/app/model" "github.com/lzh-1625/go_process_manager/log" + "github.com/lzh-1625/go_process_manager/utils" pu "github.com/shirou/gopsutil/process" ) @@ -49,10 +50,9 @@ type ProcessBase struct { Config struct { AutoRestart bool compulsoryRestart bool - statuPush bool + PushIds []int logReport bool cgroupEnable bool - PushIds []int memoryLimit *float32 cpuLimit *float32 } @@ -218,7 +218,7 @@ func (p *ProcessBase) VerifyControl() bool { func (p *ProcessBase) setProcessConfig(pconfig model.Process) { p.Config.AutoRestart = pconfig.AutoRestart p.Config.logReport = pconfig.LogReport - p.Config.statuPush = pconfig.Push + p.Config.PushIds = utils.JsonStrToStruct[[]int](pconfig.PushIds) p.Config.compulsoryRestart = pconfig.CompulsoryRestart p.Config.cgroupEnable = pconfig.CgroupEnable p.Config.memoryLimit = pconfig.MemoryLimit @@ -230,7 +230,7 @@ func (p *ProcessBase) ResetRestartTimes() { } func (p *ProcessBase) push(message string) { - if p.Config.statuPush { + if len(p.Config.PushIds) != 0 { messagePlaceholders := map[string]string{ "{$name}": p.Name, "{$user}": p.GetUserString(), diff --git a/internal/app/service/process_service.go b/internal/app/service/process_service.go index 8b4bc72..6bbcfe9 100644 --- a/internal/app/service/process_service.go +++ b/internal/app/service/process_service.go @@ -10,6 +10,7 @@ import ( "github.com/lzh-1625/go_process_manager/internal/app/model" "github.com/lzh-1625/go_process_manager/internal/app/repository" "github.com/lzh-1625/go_process_manager/log" + "github.com/lzh-1625/go_process_manager/utils" ) type processCtlService struct { @@ -200,7 +201,7 @@ func (p *processCtlService) UpdateProcessConfig(config model.Process) error { } defer result.Lock.Unlock() result.Config.logReport = config.LogReport - result.Config.statuPush = config.Push + result.Config.PushIds = utils.JsonStrToStruct[[]int](config.PushIds) result.Config.cgroupEnable = config.CgroupEnable result.Config.memoryLimit = config.MemoryLimit result.Config.cpuLimit = config.CpuLimit diff --git a/utils/str.go b/utils/str.go index 5f097c2..a63c741 100644 --- a/utils/str.go +++ b/utils/str.go @@ -1,6 +1,7 @@ package utils import ( + "encoding/json" "fmt" "math/rand" "regexp" @@ -76,3 +77,9 @@ func (k *KVStr) Build() string { } return strings.Join(strList, " , ") } + +func JsonStrToStruct[T any](str string) T { + var data T + json.Unmarshal([]byte(str), &data) + return data +}