Move keepalive out of mgm pkg

This commit is contained in:
Zoltan Papp
2023-03-30 09:59:42 +02:00
parent e376541745
commit 520c7b5d37
6 changed files with 75 additions and 47 deletions

32
keepalive/monitor.go Normal file
View File

@@ -0,0 +1,32 @@
package keepalive
import (
"sync"
"time"
"google.golang.org/grpc"
)
type ioMonitor struct {
mu sync.Mutex
grpc.ServerStream
lastSeen time.Time
}
func (l *ioMonitor) sendMsg(m interface{}) error {
l.updateLastSeen()
return l.ServerStream.SendMsg(m)
}
func (l *ioMonitor) updateLastSeen() {
l.mu.Lock()
defer l.mu.Unlock()
l.lastSeen = time.Now()
}
func (l *ioMonitor) getLastSeen() time.Time {
l.mu.Lock()
t := l.lastSeen
l.mu.Unlock()
return t
}