package cronjob import ( "fmt" "hwcollector/server/services/datacollector" "hwcollector/server/services/datapreprocessor" "os" "path/filepath" "time" "github.com/robfig/cron/v3" ) // InitCron start cron func InitCron(debug bool) *cron.Cron { cj := cron.New(cron.WithSeconds(), cron.WithLocation(time.UTC)) cj.AddFunc("1 0 0 * * *", func() { t := time.Now().UTC() newpath := filepath.Join(".", "_data_", t.Format("2006-01-02")) os.MkdirAll(newpath, os.ModePerm) }) cj.AddFunc("1 0/15 * * * *", func() { pp := datapreprocessor.NewPreProcessor(".", debug) pp.RunPath() }) cj.AddFunc("30 1/5 * * * *", func() { fmt.Println("datacollector.Start()") datacollector.Start() }) cj.Start() return cj }