support push item choice

This commit is contained in:
akrike
2025-02-09 13:13:17 +08:00
parent ed90f6b31f
commit 81351a815f
4 changed files with 14 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ type Process struct {
Cwd string `gorm:"column:cwd" json:"cwd"` Cwd string `gorm:"column:cwd" json:"cwd"`
AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"` AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"`
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"` 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"` LogReport bool `gorm:"column:log_report" json:"logReport"`
TermType constants.TerminalType `gorm:"column:term_type" json:"termType"` TermType constants.TerminalType `gorm:"column:term_type" json:"termType"`
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"` CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`

View File

@@ -14,6 +14,7 @@ import (
"github.com/lzh-1625/go_process_manager/internal/app/middle" "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/internal/app/model"
"github.com/lzh-1625/go_process_manager/log" "github.com/lzh-1625/go_process_manager/log"
"github.com/lzh-1625/go_process_manager/utils"
pu "github.com/shirou/gopsutil/process" pu "github.com/shirou/gopsutil/process"
) )
@@ -49,10 +50,9 @@ type ProcessBase struct {
Config struct { Config struct {
AutoRestart bool AutoRestart bool
compulsoryRestart bool compulsoryRestart bool
statuPush bool PushIds []int
logReport bool logReport bool
cgroupEnable bool cgroupEnable bool
PushIds []int
memoryLimit *float32 memoryLimit *float32
cpuLimit *float32 cpuLimit *float32
} }
@@ -218,7 +218,7 @@ func (p *ProcessBase) VerifyControl() bool {
func (p *ProcessBase) setProcessConfig(pconfig model.Process) { func (p *ProcessBase) setProcessConfig(pconfig model.Process) {
p.Config.AutoRestart = pconfig.AutoRestart p.Config.AutoRestart = pconfig.AutoRestart
p.Config.logReport = pconfig.LogReport 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.compulsoryRestart = pconfig.CompulsoryRestart
p.Config.cgroupEnable = pconfig.CgroupEnable p.Config.cgroupEnable = pconfig.CgroupEnable
p.Config.memoryLimit = pconfig.MemoryLimit p.Config.memoryLimit = pconfig.MemoryLimit
@@ -230,7 +230,7 @@ func (p *ProcessBase) ResetRestartTimes() {
} }
func (p *ProcessBase) push(message string) { func (p *ProcessBase) push(message string) {
if p.Config.statuPush { if len(p.Config.PushIds) != 0 {
messagePlaceholders := map[string]string{ messagePlaceholders := map[string]string{
"{$name}": p.Name, "{$name}": p.Name,
"{$user}": p.GetUserString(), "{$user}": p.GetUserString(),

View File

@@ -10,6 +10,7 @@ import (
"github.com/lzh-1625/go_process_manager/internal/app/model" "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/internal/app/repository"
"github.com/lzh-1625/go_process_manager/log" "github.com/lzh-1625/go_process_manager/log"
"github.com/lzh-1625/go_process_manager/utils"
) )
type processCtlService struct { type processCtlService struct {
@@ -200,7 +201,7 @@ func (p *processCtlService) UpdateProcessConfig(config model.Process) error {
} }
defer result.Lock.Unlock() defer result.Lock.Unlock()
result.Config.logReport = config.LogReport 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.cgroupEnable = config.CgroupEnable
result.Config.memoryLimit = config.MemoryLimit result.Config.memoryLimit = config.MemoryLimit
result.Config.cpuLimit = config.CpuLimit result.Config.cpuLimit = config.CpuLimit

View File

@@ -1,6 +1,7 @@
package utils package utils
import ( import (
"encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"regexp" "regexp"
@@ -76,3 +77,9 @@ func (k *KVStr) Build() string {
} }
return strings.Join(strList, " , ") return strings.Join(strList, " , ")
} }
func JsonStrToStruct[T any](str string) T {
var data T
json.Unmarshal([]byte(str), &data)
return data
}