mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-09-18 15:08:21 +03:00
feat: add connect stream to connection manager
This commit is contained in:
@@ -13,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type AgentConnection struct {
|
||||
stream streamConn
|
||||
stream StreamConn
|
||||
heartbeat heartbeatStore
|
||||
log zerolog.Logger
|
||||
status statusAgent
|
||||
status StatusAgent
|
||||
AgentID string
|
||||
response *ResponseStore
|
||||
ctx context.Context
|
||||
@@ -24,7 +24,7 @@ type AgentConnection struct {
|
||||
heartbeatTimeoutMS int
|
||||
}
|
||||
|
||||
func newAgentConnection(agentID string, stream streamConn, heartbeat heartbeatStore, status statusAgent, heartbeatTimeoutMS int, logger zerolog.Logger) *AgentConnection {
|
||||
func newAgentConnection(agentID string, stream StreamConn, heartbeat heartbeatStore, status StatusAgent, heartbeatTimeoutMS int, logger zerolog.Logger) *AgentConnection {
|
||||
response := NewResponseStore()
|
||||
logger = logger.With().Str("agentID", agentID).Logger()
|
||||
ctx, cancel := context.WithCancel(stream.Context())
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
domainHub "github.com/lorsanstand/HomeOps-Hub/hub/internal/domain"
|
||||
)
|
||||
|
||||
type streamConn interface {
|
||||
type StreamConn interface {
|
||||
Send(request *pb.ServerCommandRequest) error
|
||||
Recv() (*pb.AgentEvent, error)
|
||||
Context() context.Context
|
||||
@@ -17,11 +17,11 @@ type heartbeatStore interface {
|
||||
CreateHeartbeat(ctx context.Context, heartbeat domainHub.CreateHeartbeatModel) error
|
||||
}
|
||||
|
||||
type statusAgent interface {
|
||||
type StatusAgent interface {
|
||||
Offline()
|
||||
Online()
|
||||
}
|
||||
|
||||
type statusNotifier interface {
|
||||
New(AgentID string) statusAgent
|
||||
New(agentID string) StatusAgent
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func NewConnectionManager(heartbeat heartbeatStore, status statusNotifier, logge
|
||||
return &ConnectionManager{heartbeat: heartbeat, log: logger, status: status, agentConnStore: NewAgentConnStore()}
|
||||
}
|
||||
|
||||
func (c *ConnectionManager) NewConnection(stream streamConn) error {
|
||||
func (c *ConnectionManager) NewConnection(stream StreamConn) error {
|
||||
AgentID, err := agentIDFromMetadata(stream.Context())
|
||||
if err != nil {
|
||||
c.log.Error().Err(err).Msg("missing agent id in metadata")
|
||||
|
||||
@@ -109,7 +109,7 @@ type statusNotifierMock struct {
|
||||
agentIDCh chan string
|
||||
}
|
||||
|
||||
func (s *statusNotifierMock) New(AgentID string) statusAgent {
|
||||
func (s *statusNotifierMock) New(AgentID string) StatusAgent {
|
||||
select {
|
||||
case s.agentIDCh <- AgentID:
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user