diff --git a/common/cool/global.go b/common/cool/global.go index e1469b51..58cecf47 100644 --- a/common/cool/global.go +++ b/common/cool/global.go @@ -42,8 +42,8 @@ func init() { sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存 sensitive.FilterOption{Type: sensitive.FilterDfa}, // 基于DFA算法 ) - Cron.Start() - + go Cron.Run() + // if err != nil { // log.Fatalf("敏感词服务启动失败, err:%v", err) // return diff --git a/common/utils/cronex/cronex.go b/common/utils/cronex/cronex.go index dd1b2092..c0371160 100644 --- a/common/utils/cronex/cronex.go +++ b/common/utils/cronex/cronex.go @@ -40,12 +40,6 @@ func (c *Cronex) Run() { c.Run() } -// 异步运行消费者循环 -func (c *Cronex) Start() { - //ants.Submit(c.Run) - go c.Run() -} - // 关闭cronex的任务循环 func (c *Cronex) Stop() { c.Stop() diff --git a/common/utils/cronex/cronex_test.go b/common/utils/cronex/cronex_test.go index 86b91dca..60c11755 100644 --- a/common/utils/cronex/cronex_test.go +++ b/common/utils/cronex/cronex_test.go @@ -15,7 +15,7 @@ func Test_Cronex(t *testing.T) { } cron := New() - cron.Start() //运行事件循环 + go cron.Run() count := 2 durationChan := make(chan time.Duration, count) @@ -82,7 +82,7 @@ func Test_Cronex_ParseNext(t *testing.T) { left := first + time.Duration(0.8*float64(time.Second)) right := first + time.Duration(1.2*float64(time.Second)) - tv := now.Sub(time.Now()) + tv := time.Until(now) if tv < left || tv > right { t.Logf("tv(%v), tv < left(%v) || tv > right(%v)", tv, left, right) return @@ -95,7 +95,7 @@ func Test_Multiple(t *testing.T) { cron := New() count := int32(0) - cron.Start() + go cron.Run() max := int32(10) for i := int32(0); i < max; i++ { cron.AddFunc("* * * * * *", func() {