From c50530d4bb12961c9a68d58fb9d540eb8411327e Mon Sep 17 00:00:00 2001 From: Yun Date: Mon, 22 Sep 2025 13:51:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E6=B7=BB=E5=8A=A0traceid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cluster.go b/cluster.go index e6c1f98..0c3795b 100644 --- a/cluster.go +++ b/cluster.go @@ -32,12 +32,12 @@ type Cluster struct { keyPrefix string // key前缀 location *time.Location // 根据时区计算的时间 - lockKey string // 全局计算的key - zsetKey string // 有序集合的key - listKey string // 可执行的任务列表的key - setKey string // 重入集合的key - heartbeatKey string // 心跳的Key - leaderKey string // 上报当前的Leader + lockKey string // 全局计算的key + zsetKey string // 有序集合的key + listKey string // 可执行的任务列表的key + setKey string // 重入集合的key + heartbeatKey string // 心跳的Key + leaderKey string // 上报当前的Leader executeInfoKey string // 执行情况的key priority *priority.Priority // 全局优先级 @@ -615,9 +615,9 @@ func (l *Cluster) processTask(taskId string) { l.logger.Infof(ctx, "doTask timer begin taskId:%s", taskId) // 上报执行情况 - executeVal := fmt.Sprintf("%s|%s|%s",taskId,l.instanceId,begin.Format(time.RFC3339Nano)) - l.redis.ZAdd(ctx,l.executeInfoKey,&redis.Z{ - Score: float64(begin.UnixMilli()), + executeVal := fmt.Sprintf("%s|%s|%s|%s", taskId, l.instanceId, u.String(), begin.Format(time.RFC3339Nano)) + l.redis.ZAdd(ctx, l.executeInfoKey, &redis.Z{ + Score: float64(begin.UnixMilli()), Member: executeVal, }) @@ -644,7 +644,6 @@ func (l *Cluster) processTask(taskId string) { } defer lock.Unlock() - defer func() { if err := recover(); err != nil { l.logger.Errorf(ctx, "doTask timer:回调任务panic err:%+v stack:%s", err, string(debug.Stack())) @@ -653,8 +652,6 @@ func (l *Cluster) processTask(taskId string) { l.logger.Infof(ctx, "doTask timer:执行任务耗时:%s %dms", taskId, time.Since(begin).Milliseconds()) }() - - // 执行任务 if err := t.Callback(ctx, t.ExtendData); err != nil { l.logger.Errorf(ctx, "doTask timer:执行任务失败:%s %+v", taskId, err)