add: cron job (#2)
This commit is contained in:
parent
914e93086a
commit
85ccd47bb6
1
go.mod
1
go.mod
|
@ -20,6 +20,7 @@ require (
|
||||||
github.com/onsi/ginkgo v1.16.4 // indirect
|
github.com/onsi/ginkgo v1.16.4 // indirect
|
||||||
github.com/onsi/gomega v1.13.0 // indirect
|
github.com/onsi/gomega v1.13.0 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.2.0
|
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/smacker/opentracing-gorm v0.0.0-20181207094635-cd4974441042 // indirect
|
||||||
github.com/soheilhy/cmux v0.1.5
|
github.com/soheilhy/cmux v0.1.5
|
||||||
github.com/spf13/viper v1.7.1
|
github.com/spf13/viper v1.7.1
|
||||||
|
|
|
@ -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 {}
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
3
main.go
3
main.go
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Date: 2021-03-21 19:54:57
|
* @Date: 2021-03-21 19:54:57
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-06-20 19:45:38
|
* @LastEditTime: 2021-07-08 13:59:06
|
||||||
* @FilePath: /potato/main.go
|
* @FilePath: /potato/main.go
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
@ -33,6 +33,7 @@ func main() {
|
||||||
global.GO_DB = initialize.Gorm()
|
global.GO_DB = initialize.Gorm()
|
||||||
global.GO_REDIS = initialize.Redis()
|
global.GO_REDIS = initialize.Redis()
|
||||||
global.GO_TRACER = initialize.Tracer()
|
global.GO_TRACER = initialize.Tracer()
|
||||||
|
initialize.Cron()
|
||||||
|
|
||||||
defer global.GO_DB.Close()
|
defer global.GO_DB.Close()
|
||||||
defer global.GO_REDIS.Close()
|
defer global.GO_REDIS.Close()
|
||||||
|
|
Loading…
Reference in New Issue