diff --git a/go.mod b/go.mod index 11c2c62..abf0fbf 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/onsi/ginkgo v1.16.4 // indirect github.com/onsi/gomega v1.13.0 // indirect github.com/opentracing/opentracing-go v1.2.0 + github.com/robfig/cron/v3 v3.0.0 github.com/smacker/opentracing-gorm v0.0.0-20181207094635-cd4974441042 // indirect github.com/soheilhy/cmux v0.1.5 github.com/spf13/viper v1.7.1 diff --git a/initialize/cron.go b/initialize/cron.go new file mode 100644 index 0000000..8060bc9 --- /dev/null +++ b/initialize/cron.go @@ -0,0 +1,22 @@ +/* + * @Date: 2021-07-08 13:54:38 + * @LastEditors: viletyy + * @LastEditTime: 2021-07-08 14:01:18 + * @FilePath: /potato/initialize/cron.go + */ +package initialize + +import ( + "github.com/robfig/cron/v3" + "github.com/viletyy/potato/internal/job" +) + +func Cron() { + c := cron.New() + + c.AddJob("* * * * *", job.TestJob{}) + + c.Start() + + select {} +} diff --git a/internal/job/test_job.go b/internal/job/test_job.go new file mode 100644 index 0000000..a3398aa --- /dev/null +++ b/internal/job/test_job.go @@ -0,0 +1,15 @@ +/* + * @Date: 2021-07-08 14:01:46 + * @LastEditors: viletyy + * @LastEditTime: 2021-07-08 14:02:36 + * @FilePath: /potato/internal/job/test_job.go + */ +package job + +import "fmt" + +type TestJob struct{} + +func (t TestJob) Run() { + fmt.Println("i'm test job") +} diff --git a/main.go b/main.go index 9323dbd..4f1ff71 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ /* * @Date: 2021-03-21 19:54:57 * @LastEditors: viletyy - * @LastEditTime: 2021-06-20 19:45:38 + * @LastEditTime: 2021-07-08 13:59:06 * @FilePath: /potato/main.go */ package main @@ -33,6 +33,7 @@ func main() { global.GO_DB = initialize.Gorm() global.GO_REDIS = initialize.Redis() global.GO_TRACER = initialize.Tracer() + initialize.Cron() defer global.GO_DB.Close() defer global.GO_REDIS.Close()