wip: feat(wingmate): convert from new config to task
This commit is contained in:
parent
1926598c0f
commit
2c9bc8b56d
@ -3,7 +3,7 @@ all:
|
||||
go build -v
|
||||
|
||||
clean:
|
||||
rm version.txt
|
||||
echo "dev" > version.txt
|
||||
go clean -i -cache -testcache
|
||||
|
||||
install:
|
||||
|
||||
@ -3,7 +3,7 @@ all:
|
||||
go build -v
|
||||
|
||||
clean:
|
||||
rm version.txt
|
||||
echo "dev" > version.txt
|
||||
go clean -i -cache -testcache
|
||||
|
||||
install:
|
||||
|
||||
@ -3,7 +3,7 @@ all:
|
||||
go build -v
|
||||
|
||||
clean:
|
||||
rm version.txt
|
||||
echo "dev" > version.txt
|
||||
go clean -i -cache -testcache
|
||||
|
||||
install:
|
||||
|
||||
@ -3,7 +3,7 @@ all:
|
||||
go build -v
|
||||
|
||||
clean:
|
||||
rm version.txt
|
||||
echo "dev" > version.txt
|
||||
go clean -i -cache -testcache
|
||||
|
||||
install:
|
||||
|
||||
@ -19,26 +19,47 @@ func convert(cfg *config.Config) *wConfig {
|
||||
tasks: task.NewTasks(),
|
||||
}
|
||||
|
||||
for _, s := range cfg.Service {
|
||||
st := task.NewServiceTask(s.Name).SetCommand(s.Command...).SetEnv(s.Environ...)
|
||||
st.SetFlagSetsid(s.Setsid).SetWorkingDir(s.WorkingDir)
|
||||
st.SetUser(s.User).SetGroup(s.Group).SetStartSecs(s.StartSecs).SetPidFile(s.PidFile)
|
||||
retval.tasks.AddService(st)
|
||||
}
|
||||
|
||||
for _, s := range cfg.ServiceV0 {
|
||||
retval.tasks.AddV0Service(s)
|
||||
|
||||
}
|
||||
|
||||
var schedule task.CronSchedule
|
||||
for _, c := range cfg.CronV0 {
|
||||
schedule.Minute = convertSchedule(c.Minute)
|
||||
schedule.Hour = convertSchedule(c.Hour)
|
||||
schedule.DoM = convertSchedule(c.DoM)
|
||||
schedule.Month = convertSchedule(c.Month)
|
||||
schedule.DoW = convertSchedule(c.DoW)
|
||||
|
||||
schedule = configToTaskCronSchedule(c.CronSchedule)
|
||||
retval.tasks.AddV0Cron(schedule, c.Command)
|
||||
}
|
||||
|
||||
for _, c := range cfg.Cron {
|
||||
schedule = configToTaskCronSchedule(c.CronSchedule)
|
||||
|
||||
ct := task.NewCronTask(c.Name).SetCommand(c.Command...).SetEnv(c.Environ...)
|
||||
ct.SetFlagSetsid(c.Setsid).SetWorkingDir(c.WorkingDir).SetUser(c.User).SetGroup(c.Group)
|
||||
ct.SetSchedule(schedule)
|
||||
|
||||
retval.tasks.AddCron(ct)
|
||||
}
|
||||
|
||||
return retval
|
||||
}
|
||||
|
||||
func convertSchedule(cfg config.CronTimeSpec) task.CronTimeSpec {
|
||||
func configToTaskCronSchedule(cfgSchedule config.CronSchedule) (taskSchedule task.CronSchedule) {
|
||||
taskSchedule.Minute = configToTaskCronTimeSpec(cfgSchedule.Minute)
|
||||
taskSchedule.Hour = configToTaskCronTimeSpec(cfgSchedule.Hour)
|
||||
taskSchedule.DoM = configToTaskCronTimeSpec(cfgSchedule.DoM)
|
||||
taskSchedule.Month = configToTaskCronTimeSpec(cfgSchedule.Month)
|
||||
taskSchedule.DoW = configToTaskCronTimeSpec(cfgSchedule.DoW)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func configToTaskCronTimeSpec(cfg config.CronTimeSpec) task.CronTimeSpec {
|
||||
switch v := cfg.(type) {
|
||||
case *config.SpecAny:
|
||||
return task.NewCronAnySpec()
|
||||
|
||||
@ -17,11 +17,7 @@ type CronTimeSpec interface {
|
||||
}
|
||||
|
||||
type Cron struct {
|
||||
Minute CronTimeSpec
|
||||
Hour CronTimeSpec
|
||||
DoM CronTimeSpec
|
||||
Month CronTimeSpec
|
||||
DoW CronTimeSpec
|
||||
CronSchedule
|
||||
Command string
|
||||
}
|
||||
|
||||
|
||||
1
config/util.go
Normal file
1
config/util.go
Normal file
@ -0,0 +1 @@
|
||||
package config
|
||||
12
task/cron.go
12
task/cron.go
@ -133,13 +133,13 @@ func (c *CronTask) Command() []string {
|
||||
}
|
||||
|
||||
func (c *CronTask) Environ() []string {
|
||||
panic("not implemented")
|
||||
return nil
|
||||
retval := make([]string, len(c.environ))
|
||||
copy(retval, c.environ)
|
||||
return retval
|
||||
}
|
||||
|
||||
func (c *CronTask) Setsid() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
return c.setsid
|
||||
}
|
||||
|
||||
func (c *CronTask) UserGroup() wminit.UserGroup {
|
||||
@ -147,11 +147,11 @@ func (c *CronTask) UserGroup() wminit.UserGroup {
|
||||
}
|
||||
|
||||
func (c *CronTask) WorkingDir() string {
|
||||
panic("not implemented")
|
||||
return ""
|
||||
return c.workingDir
|
||||
}
|
||||
|
||||
func (c *CronTask) Status() wminit.TaskStatus {
|
||||
//TODO: implement me!
|
||||
panic("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
40
task/task.go
40
task/task.go
@ -55,6 +55,7 @@ func (ts *Tasks) Crones() []wminit.CronTask {
|
||||
}
|
||||
|
||||
func (ts *Tasks) Get(name string) (wminit.Task, error) {
|
||||
//TODO: implement me!
|
||||
panic("not implemented")
|
||||
return nil, nil
|
||||
}
|
||||
@ -67,6 +68,7 @@ type ServiceTask struct {
|
||||
background bool
|
||||
workingDir string
|
||||
startSecs uint
|
||||
pidFile string
|
||||
userGroup
|
||||
}
|
||||
|
||||
@ -93,11 +95,6 @@ func (t *ServiceTask) SetFlagSetsid(flag bool) *ServiceTask {
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ServiceTask) SetFlagBackground(flag bool) *ServiceTask {
|
||||
t.background = flag
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ServiceTask) SetWorkingDir(path string) *ServiceTask {
|
||||
t.workingDir = path
|
||||
return t
|
||||
@ -118,6 +115,16 @@ func (t *ServiceTask) SetStartSecs(secs uint) *ServiceTask {
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ServiceTask) SetPidFile(path string) *ServiceTask {
|
||||
t.pidFile = path
|
||||
if len(path) > 0 {
|
||||
t.background = true
|
||||
} else {
|
||||
t.background = false
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Name() string {
|
||||
return t.name
|
||||
}
|
||||
@ -129,13 +136,13 @@ func (t *ServiceTask) Command() []string {
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Environ() []string {
|
||||
panic("not implemented")
|
||||
return nil
|
||||
retval := make([]string, len(t.environ))
|
||||
copy(retval, t.environ)
|
||||
return retval
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Setsid() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
return t.setsid
|
||||
}
|
||||
|
||||
func (t *ServiceTask) UserGroup() wminit.UserGroup {
|
||||
@ -143,38 +150,37 @@ func (t *ServiceTask) UserGroup() wminit.UserGroup {
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Background() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
return t.background
|
||||
}
|
||||
|
||||
func (t *ServiceTask) WorkingDir() string {
|
||||
panic("not implemented")
|
||||
return ""
|
||||
return t.workingDir
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Status() wminit.TaskStatus {
|
||||
//TODO: implement me!
|
||||
panic("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ServiceTask) AutoStart() bool {
|
||||
//TODO: implement me!
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *ServiceTask) AutoRestart() bool {
|
||||
//TODO: implement me!
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *ServiceTask) StartSecs() uint {
|
||||
panic("not implemented")
|
||||
return 0
|
||||
return t.startSecs
|
||||
}
|
||||
|
||||
func (t *ServiceTask) PidFile() string {
|
||||
panic("not implemented")
|
||||
return ""
|
||||
return t.pidFile
|
||||
}
|
||||
|
||||
type userGroup struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user