Browse Source

清理逻辑完善

Tao Zhang 5 years ago
parent
commit
0a6f2d58d4
2 changed files with 15 additions and 13 deletions
  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)
+		}
+	}
+}