You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
583 B
22 lines
583 B
package gojobs
|
|
|
|
import (
|
|
"context"
|
|
"github.com/robfig/cron/v3"
|
|
"time"
|
|
)
|
|
|
|
// Ping 心跳
|
|
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.cornKeyPrefix+"_"+j.config.cornKeyCustom, j.config.cornKeyCustom, 3*time.Second).Result()
|
|
if j.config.logDebug == true {
|
|
j.logClient.Infof(ctx, "[jobs.Ping] %s %s %v %s", j.config.cornKeyPrefix+"_"+j.config.cornKeyCustom, j.config.cornKeyCustom, result, err)
|
|
}
|
|
})
|
|
c.Start()
|
|
defer c.Stop()
|
|
select {}
|
|
}
|