wip: refactor(config): added new structures
wip: feat(task): renamed structure
This commit is contained in:
parent
98d57cda84
commit
6a40403434
@ -23,6 +23,36 @@ type Config struct {
|
||||
Cron []*Cron
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
Command []string `yaml:"command"`
|
||||
Environ []string `yaml:"environ"`
|
||||
Setsid bool `yaml:"setsid"`
|
||||
User string `yaml:"user"`
|
||||
Group string `yaml:"group"`
|
||||
Background bool `yaml:"background"`
|
||||
WorkingDir string `yaml:"working_dir"`
|
||||
}
|
||||
|
||||
type ServiceTask struct {
|
||||
Task `yaml:",inline"`
|
||||
AutoStart bool `yaml:"autostart"`
|
||||
AutoRestart bool `yaml:"autorestart"`
|
||||
}
|
||||
|
||||
type CronTask struct {
|
||||
CronSchedule `yaml:"-"`
|
||||
Task `yaml:",inline"`
|
||||
Schedule string `yaml:"schedule"`
|
||||
}
|
||||
|
||||
type CronSchedule struct {
|
||||
Minute CronTimeSpec
|
||||
Hour CronTimeSpec
|
||||
DoM CronTimeSpec
|
||||
Month CronTimeSpec
|
||||
DoW CronTimeSpec
|
||||
}
|
||||
|
||||
func Read() (*Config, error) {
|
||||
viper.SetEnvPrefix(EnvPrefix)
|
||||
viper.BindEnv(EnvConfigPath)
|
||||
|
||||
1
config/yaml.go
Normal file
1
config/yaml.go
Normal file
@ -0,0 +1 @@
|
||||
package config
|
||||
24
task/task.go
24
task/task.go
@ -17,7 +17,7 @@ func NewTasks() *Tasks {
|
||||
}
|
||||
|
||||
func (ts *Tasks) AddV0Service(path string) {
|
||||
ts.services = append(ts.services, &Task{
|
||||
ts.services = append(ts.services, &ServiceTask{
|
||||
name: path,
|
||||
command: []string{path},
|
||||
})
|
||||
@ -56,57 +56,57 @@ func (ts *Tasks) Get(name string) (wminit.Task, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
type ServiceTask struct {
|
||||
name string
|
||||
command []string
|
||||
}
|
||||
|
||||
func (t *Task) Name() string {
|
||||
func (t *ServiceTask) Name() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *Task) Command() []string {
|
||||
func (t *ServiceTask) Command() []string {
|
||||
retval := make([]string, len(t.command))
|
||||
copy(retval, t.command)
|
||||
return retval
|
||||
}
|
||||
|
||||
func (t *Task) Environ() []string {
|
||||
func (t *ServiceTask) Environ() []string {
|
||||
panic("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) Setsid() bool {
|
||||
func (t *ServiceTask) Setsid() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *Task) UserGroup() wminit.UserGroup {
|
||||
func (t *ServiceTask) UserGroup() wminit.UserGroup {
|
||||
panic("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) Background() bool {
|
||||
func (t *ServiceTask) Background() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *Task) WorkingDir() string {
|
||||
func (t *ServiceTask) WorkingDir() string {
|
||||
panic("not implemented")
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t *Task) Status() wminit.TaskStatus {
|
||||
func (t *ServiceTask) Status() wminit.TaskStatus {
|
||||
panic("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) AutoStart() bool {
|
||||
func (t *ServiceTask) AutoStart() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *Task) AutoRestart() bool {
|
||||
func (t *ServiceTask) AutoRestart() bool {
|
||||
panic("not implemented")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -33,11 +33,11 @@ func TestCronV0(t *testing.T) {
|
||||
func TestTasks_List(t *testing.T) {
|
||||
tasks := NewTasks()
|
||||
tasks.services = []wminit.ServiceTask{
|
||||
&Task{
|
||||
&ServiceTask{
|
||||
name: "one",
|
||||
command: []string{"/path/to/executable"},
|
||||
},
|
||||
&Task{
|
||||
&ServiceTask{
|
||||
name: "two",
|
||||
command: []string{"/path/to/executable"},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user