preparation for v0.2.0 #3

Merged
suyono merged 32 commits from wip2 into main 2024-09-22 11:44:07 +10:00
4 changed files with 45 additions and 14 deletions
Showing only changes of commit 6a40403434 - Show all commits

View File

@ -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
View File

@ -0,0 +1 @@
package config

View File

@ -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
}

View File

@ -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"},
},