28 lines
558 B
Go
28 lines
558 B
Go
package cronjob
|
|
|
|
import (
|
|
"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(".", t.Format("2006-01-02"))
|
|
os.MkdirAll(newpath, os.ModePerm)
|
|
})
|
|
cj.AddFunc("1 0/15 * * * *", func() {
|
|
pp := datapreprocessor.NewPreProcessor(".", debug)
|
|
pp.RunPath()
|
|
})
|
|
|
|
cj.Start()
|
|
return cj
|
|
}
|