From 15831194c80fd1e0bd56e91dd76deb1a75c94a83 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 10 十一月 2023 17:23:35 +0800 Subject: [PATCH] 优化 --- crontask/cron_task.go | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/crontask/cron_task.go b/crontask/cron_task.go index aca64dd..153182a 100644 --- a/crontask/cron_task.go +++ b/crontask/cron_task.go @@ -19,6 +19,9 @@ var s *gocron.Scheduler +func init() { + s = gocron.NewScheduler(time.UTC) +} func StartTask(isMaster bool) error { finishNumberTimeInterval := conf.Conf.PLC.FinishNumberTimeInterval totalNumberTimeInterval := conf.Conf.PLC.TotalNumberTimeInterval @@ -28,7 +31,6 @@ if totalNumberTimeInterval == 0 { totalNumberTimeInterval = 60 } - s = gocron.NewScheduler(time.UTC) _, err := s.Every(finishNumberTimeInterval).Seconds().Do(func() { plcConfig, code := service.NewDevicePlcService().GetDevicePlc() if code != ecode.OK { @@ -139,6 +141,7 @@ func RestartTask(isMaster bool) error { if s != nil { s.Stop() + s.Clear() } return StartTask(isMaster) } -- Gitblit v1.8.0