From e8f65e16f9003358b6fbe2b860aa7e99ff329367 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 28 八月 2023 10:51:13 +0800 Subject: [PATCH] 定时任务查询完成数,查到值为0不写入内存 --- crontask/cron_task.go | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crontask/cron_task.go b/crontask/cron_task.go index c8702b8..e27df3e 100644 --- a/crontask/cron_task.go +++ b/crontask/cron_task.go @@ -3,6 +3,7 @@ import ( "apsClient/constvar" "apsClient/pkg/ecode" + "apsClient/pkg/logx" "apsClient/service" "github.com/go-co-op/gocron" "time" @@ -10,30 +11,32 @@ func InitTask() error { s := gocron.NewScheduler(time.UTC) - _, err := s.Every(2).Seconds().StartImmediately().Do(func() { + _, err := s.Every(9).Seconds().StartImmediately().Do(func() { plcConfig, code := service.NewDevicePlcService().GetDevicePlc() if code != ecode.OK { return } finishNumber, err := service.PlcRead(plcConfig, constvar.PlcStartAddressTypeFinishNumber) - if err == nil { + if err == nil && finishNumber != 0 { service.PlcCacheSet(constvar.PlcCacheKeyFinishNumber, finishNumber) } + logx.Infof("plc read finish number:%v, err:%v", finishNumber, err) }) if err != nil { return err } - s.Every(1).Minutes().StartImmediately().Do(func() { + s.Every(60).Seconds().StartImmediately().Do(func() { plcConfig, code := service.NewDevicePlcService().GetDevicePlc() if code != ecode.OK { return } totalNumber, err := service.PlcRead(plcConfig, constvar.PlcStartAddressTypeTotalNumber) - if err == nil { + if err == nil && totalNumber != 0 { service.PlcCacheSet(constvar.PlcCacheKeyTotalNumber, totalNumber) } + logx.Infof("plc read total number:%v, err:%v", totalNumber, err) }) s.StartAsync() -- Gitblit v1.8.0