This commit is contained in:
Yun
2023-09-09 15:42:13 +08:00
parent 1cc64264f7
commit 3200f19d63
2 changed files with 5 additions and 6 deletions
+4 -6
View File
@@ -45,7 +45,7 @@ func InitCluster(ctx context.Context, red *redis.Client) *cluster {
// 监听任务 // 监听任务
go clu.watch() go clu.watch()
timer := time.NewTicker(time.Millisecond*100) timer := time.NewTicker(time.Millisecond * 100)
go func(ctx context.Context, red *redis.Client) { go func(ctx context.Context, red *redis.Client) {
Loop: Loop:
@@ -230,9 +230,7 @@ func (c *cluster) watch() {
fmt.Println("watch err:", err) fmt.Println("watch err:", err)
continue continue
} }
for _, val := range keys { go doTask(c.ctx, c.redis, keys[1])
go doTask(c.ctx, c.redis, val)
}
} }
} }
@@ -250,7 +248,7 @@ func doTask(ctx context.Context, red *redis.Client, taskId string) {
val, ok := clusterWorkerList.Load(taskId) val, ok := clusterWorkerList.Load(taskId)
if !ok { if !ok {
fmt.Println("doTask timer:任务不存在") fmt.Println("doTask timer:任务不存在", taskId)
return return
} }
t := val.(timerStr) t := val.(timerStr)
@@ -259,7 +257,7 @@ func doTask(ctx context.Context, red *redis.Client, taskId string) {
lock := lockx.NewGlobalLock(ctx, red, taskId) lock := lockx.NewGlobalLock(ctx, red, taskId)
tB := lock.Lock() tB := lock.Lock()
if !tB { if !tB {
fmt.Println("doTask timer:获取锁失败") fmt.Println("doTask timer:获取锁失败", taskId)
return return
} }
defer lock.Unlock() defer lock.Unlock()
+1
View File
@@ -94,6 +94,7 @@ func aa(ctx context.Context) bool {
// fmt.Println("gggggggggggggggggggggggggggg") // fmt.Println("gggggggggggggggggggggggggggg")
a, err := timer.GetExtendParams(ctx) a, err := timer.GetExtendParams(ctx)
fmt.Printf("%+v %+v \n\n", a, err) fmt.Printf("%+v %+v \n\n", a, err)
time.Sleep(time.Second*5)
return true return true
} }