소스 검색

清理逻辑完善

Tao Zhang 5 년 전
부모
커밋
0a6f2d58d4
2개의 변경된 파일15개의 추가작업 그리고 13개의 파일을 삭제
  1. 0 12
      server/heartbeatService.go
  2. 15 1
      server/serviceStore.go

+ 0 - 12
server/heartbeatService.go

@@ -26,15 +26,3 @@ func (h *Heartbeat) PutStream(cliStr proto.HeartBeat_PutStreamServer) error {
 	return nil
 }
 
-//过期服务清理
-func ClearTimeoutService(ttl int64) {
-	timeout := ttl * 2
-	tm := time.NewTicker(time.Duration(ttl) * time.Second)
-	for {
-		select {
-		case <-tm.C:
-			//TODO 过滤过期服务
-			RemoveTimeoutService(timeout)
-		}
-	}
-}

+ 15 - 1
server/serviceStore.go

@@ -271,7 +271,7 @@ func timeoutFilterFactory(timeout int64) func(interface{}) bool {
 		if !ok {
 			return false
 		}
-		return time.Now().Unix()-obj.LastTtlTime < limit
+		return !(time.Now().Unix()-obj.LastTtlTime > limit)
 	}
 }
 
@@ -328,3 +328,17 @@ func ClearTimeoutUsedResource(ttl int64) {
 		}
 	}
 }
+
+
+//过期服务清理
+func ClearTimeoutService(ttl int64) {
+	timeout := ttl * 2
+	tm := time.NewTicker(time.Duration(ttl) * time.Second)
+	for {
+		select {
+		case <-tm.C:
+			//TODO 过滤过期服务
+			RemoveTimeoutService(timeout)
+		}
+	}
+}