fix(work): storage worker

This commit is contained in:
bandl 2021-10-28 11:56:05 +08:00
parent 686c032f34
commit dce8739514
2 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package lru package lru
import ( import (
"fmt"
"sync" "sync"
"time" "time"
@ -36,7 +35,6 @@ func (l *lruTTl) setKeys(key *proto.BaseKey) int64 {
func (l *lruTTl) ttlKeyToMemoryBySecond() { func (l *lruTTl) ttlKeyToMemoryBySecond() {
t := time.Now() t := time.Now()
values := l.sk.PopLeft(float64(t.Unix())) values := l.sk.PopLeft(float64(t.Unix()))
fmt.Println(len(values))
for _, val := range values { for _, val := range values {
l.memoryKey <- val.(string) l.memoryKey <- val.(string)

View File

@ -68,18 +68,21 @@ func (lru *SingleCache) lruTtlWork() {
} }
return keys, nil return keys, nil
}) })
cleanTTlTicker := time.NewTicker(500 * time.Millisecond) cleanTTlTicker := time.NewTicker(500 * time.Millisecond)
defer cleanTTlTicker.Stop() defer cleanTTlTicker.Stop()
for { for {
// 清理事件 // 清理事件
<-cleanTTlTicker.C <-cleanTTlTicker.C
ttlEvent := lru.lruCleanProduce.NewEvent(TtlEventName)
ttlEvent.SetValue(WorkFuncEventKey, work)
if len(lru.lruTtlManage.memoryKey) == 0 { if len(lru.lruTtlManage.memoryKey) == 0 {
continue continue
} }
ttlEvent := lru.lruCleanProduce.NewEvent(TtlEventName)
ttlEvent.SetValue(WorkFuncEventKey, work)
ttlEvent.InitWaitEvent() ttlEvent.InitWaitEvent()
lru.lruCleanProduce.Call(ctx, ttlEvent) lru.lruCleanProduce.Call(ctx, ttlEvent)
keys, err := ttlEvent.StartWaitEvent(time.Second * 2) keys, err := ttlEvent.StartWaitEvent(time.Second * 2)
lru.lruCleanProduce.Recovery(ttlEvent) lru.lruCleanProduce.Recovery(ttlEvent)