+23
-2
@@ -7,19 +7,26 @@ import (
|
||||
"strings"
|
||||
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
confLoader "github.com/otakukaze/config-loader"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server Server `yaml:"server"`
|
||||
Listens []Listen `yaml:"listens"`
|
||||
Server Server `yaml:"server"`
|
||||
Listens []Listen `yaml:"listens"`
|
||||
CronJobs []CronJob `yaml:"cron_jobs"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Port int `yaml:"port" env:"SERVER_PORT" default:"10230"`
|
||||
}
|
||||
|
||||
type CronJob struct {
|
||||
CronTime string `yaml:"cron_time"`
|
||||
Script string `yaml:"script"`
|
||||
}
|
||||
|
||||
type Listen struct {
|
||||
HTTP *HTTPListen `yaml:"http"`
|
||||
}
|
||||
@@ -88,5 +95,19 @@ func Load(p ...string) (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// check cronJob
|
||||
cronParser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
|
||||
for _, v := range cfg.CronJobs {
|
||||
_, err := cronParser.Parse(v.CronTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check script exists
|
||||
if !tools.CheckExists(v.Script, false) {
|
||||
return nil, errors.WithStack(fmt.Errorf("cron (%s) script not exists: %s\n", v.CronTime, v.Script))
|
||||
}
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user