优化
This commit is contained in:
+5
-4
@@ -104,19 +104,19 @@ func (c *cluster) AddTimer(ctx context.Context, uniqueKey string, spaceTime time
|
|||||||
})
|
})
|
||||||
execTime[uniqueKey] = nextTime
|
execTime[uniqueKey] = nextTime
|
||||||
n, _ := json.Marshal(execTime)
|
n, _ := json.Marshal(execTime)
|
||||||
fmt.Println("execTime:", execTime, string(n))
|
// fmt.Println("execTime:", execTime, string(n))
|
||||||
p.Set(ctx, c.nextKey, string(n), 0)
|
p.Set(ctx, c.nextKey, string(n), 0)
|
||||||
|
|
||||||
_, err := p.Exec(ctx)
|
_, err := p.Exec(ctx)
|
||||||
|
|
||||||
fmt.Println("添加", err)
|
// fmt.Println("添加", err)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算下一次执行的时间
|
// 计算下一次执行的时间
|
||||||
func (c *cluster) computeTime() {
|
func (c *cluster) computeTime() {
|
||||||
log.Println("begin computer")
|
// log.Println("begin computer")
|
||||||
ctx, cancel := context.WithCancel(c.ctx)
|
ctx, cancel := context.WithCancel(c.ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -174,7 +174,8 @@ func (c *cluster) computeTime() {
|
|||||||
// log.Println("B", string(b))
|
// log.Println("B", string(b))
|
||||||
|
|
||||||
_, err := p.Exec(ctx)
|
_, err := p.Exec(ctx)
|
||||||
fmt.Println(err)
|
_ = err
|
||||||
|
// fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 递归遍历获取执行时间
|
// 递归遍历获取执行时间
|
||||||
|
|||||||
+3
-3
@@ -89,9 +89,9 @@ func re() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func aa(ctx context.Context) bool {
|
func aa(ctx context.Context) bool {
|
||||||
fmt.Println(time.Now().Format(time.RFC3339))
|
// fmt.Println(time.Now().Format(time.RFC3339))
|
||||||
fmt.Println("gggggggggggggggggggggggggggg")
|
// fmt.Println("gggggggggggggggggggggggggggg")
|
||||||
a, err := timer.GetExtendParams(ctx)
|
a, err := timer.GetExtendParams(ctx)
|
||||||
fmt.Printf("%+v %+v", a, err)
|
fmt.Printf("%+v %+v \n\n", a, err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
|
|||||||
fmt.Println("redis init error")
|
fmt.Println("redis init error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Redis = client
|
// Redis = client
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -67,7 +67,9 @@ func (g *globalLock) Unlock() bool {
|
|||||||
// 刷新锁
|
// 刷新锁
|
||||||
func (g *globalLock) Refresh() {
|
func (g *globalLock) Refresh() {
|
||||||
go func() {
|
go func() {
|
||||||
ctx = context.WithTimeout(g.ctx, time.Second*30)
|
ctx,cancel := context.WithTimeout(g.ctx, time.Second*30)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
t := time.NewTicker(time.Second)
|
t := time.NewTicker(time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user