From f56537c5f3ac0d1dc8051c9f8d92dfedf9340b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Fri, 12 Aug 2022 11:11:45 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=E5=BF=83=E8=B7=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- const.go | 2 +- jobs_gorm_redis_ping.go | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/const.go b/const.go index d0c84a4..5f8696c 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package gojobs -const Version = "1.0.47" +const Version = "1.0.48" diff --git a/jobs_gorm_redis_ping.go b/jobs_gorm_redis_ping.go index a08db31..b1fb133 100644 --- a/jobs_gorm_redis_ping.go +++ b/jobs_gorm_redis_ping.go @@ -2,16 +2,17 @@ package gojobs import ( "context" + "github.com/robfig/cron/v3" "log" ) // Ping 心跳 -func (j *JobsGorm) Ping(ctx context.Context) error { - result, err := j.redisClient.Set(ctx, j.config.cornKeyIp, j.config.outsideIp, 5).Result() - - if j.config.debug == true { - log.Println("gojobs.Ping", j.config.cornKeyIp, j.config.outsideIp, result, err) - } - - return err +func (j *JobsGorm) Ping(ctx context.Context) { + c := cron.New(cron.WithSeconds()) + _, _ = c.AddFunc(GetSeconds(2).Spec(), func() { + result, err := j.redisClient.Set(ctx, j.config.cornKeyIp, j.config.outsideIp, 3).Result() + if j.config.debug == true { + log.Println("JOBS心跳", j.config.cornKeyIp, j.config.outsideIp, result, err) + } + }) }