Refactor stream management: rename stream methods to use 'Client' prefix for clarity and update related logic in gRPC and manager files
This commit is contained in:
@@ -39,7 +39,7 @@ func NewManager(router *router.Router) *Manager {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) StartStream() (uuid.UUID, error) {
|
||||
func (m *Manager) StartClientStream() (uuid.UUID, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -50,7 +50,7 @@ func (m *Manager) StartStream() (uuid.UUID, error) {
|
||||
OutChannel: nil,
|
||||
Timer: time.AfterFunc(1*time.Minute, func() {
|
||||
fmt.Printf("stream %s expired due to inactivity\n", streamID)
|
||||
err := m.StopStream(streamID)
|
||||
err := m.StopClientStream(streamID)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to stop stream after timeout: %v\n", err)
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (m *Manager) StartStream() (uuid.UUID, error) {
|
||||
return streamID, nil
|
||||
}
|
||||
|
||||
func (m *Manager) ConfigureStream(streamID uuid.UUID, newIds []domain.Identifier) error {
|
||||
func (m *Manager) ConfigureClientStream(streamID uuid.UUID, newIds []domain.Identifier) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -150,8 +150,8 @@ func (m *Manager) ConfigureStream(streamID uuid.UUID, newIds []domain.Identifier
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) StopStream(streamID uuid.UUID) error {
|
||||
m.DisconnectStream(streamID)
|
||||
func (m *Manager) StopClientStream(streamID uuid.UUID) error {
|
||||
m.DisconnectClientStream(streamID)
|
||||
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -186,7 +186,7 @@ func (m *Manager) StopStream(streamID uuid.UUID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) ConnectStream(streamID uuid.UUID) (<-chan domain.Message, error) {
|
||||
func (m *Manager) ConnectClientStream(streamID uuid.UUID) (<-chan domain.Message, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -214,7 +214,7 @@ func (m *Manager) ConnectStream(streamID uuid.UUID) (<-chan domain.Message, erro
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (m *Manager) DisconnectStream(streamID uuid.UUID) {
|
||||
func (m *Manager) DisconnectClientStream(streamID uuid.UUID) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -232,7 +232,7 @@ func (m *Manager) DisconnectStream(streamID uuid.UUID) {
|
||||
|
||||
stream.Timer = time.AfterFunc(1*time.Minute, func() {
|
||||
fmt.Printf("stream %s expired due to inactivity\n", streamID)
|
||||
err := m.StopStream(streamID)
|
||||
err := m.StopClientStream(streamID)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to stop stream after disconnect: %v\n", err)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func NewGRPCControlServer(m *manager.Manager) *GRPCControlServer {
|
||||
}
|
||||
|
||||
func (s *GRPCControlServer) StartStream(_ context.Context, _ *pb.StartStreamRequest) (*pb.StartStreamResponse, error) {
|
||||
streamID, err := s.manager.StartStream()
|
||||
streamID, err := s.manager.StartClientStream()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to start stream: %w", err)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (s *GRPCControlServer) ConfigureStream(_ context.Context, req *pb.Configure
|
||||
ids = append(ids, id)
|
||||
}
|
||||
|
||||
if err := s.manager.ConfigureStream(streamID, ids); err != nil {
|
||||
if err := s.manager.ConfigureClientStream(streamID, ids); err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "configure failed: %v", err)
|
||||
}
|
||||
return &pb.ConfigureStreamResponse{}, nil
|
||||
@@ -55,7 +55,7 @@ func (s *GRPCControlServer) StopStream(_ context.Context, req *pb.StopStreamRequ
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid stream_uuid %q: %v", req.StreamUuid, err)
|
||||
}
|
||||
if err := s.manager.StopStream(streamID); err != nil {
|
||||
if err := s.manager.StopClientStream(streamID); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to stop stream: %v", err)
|
||||
}
|
||||
return &pb.StopStreamResponse{}, nil
|
||||
|
||||
@@ -23,7 +23,7 @@ func (s *GRPCStreamingServer) ConnectStream(req *pb.ConnectStreamRequest, stream
|
||||
return fmt.Errorf("invalid UUID: %w", err)
|
||||
}
|
||||
|
||||
ch, err := s.manager.ConnectStream(streamUUID)
|
||||
ch, err := s.manager.ConnectClientStream(streamUUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect: %w", err)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func (s *GRPCStreamingServer) ConnectStream(req *pb.ConnectStreamRequest, stream
|
||||
for {
|
||||
select {
|
||||
case <-stream.Context().Done():
|
||||
s.manager.DisconnectStream(streamUUID)
|
||||
s.manager.DisconnectClientStream(streamUUID)
|
||||
return nil
|
||||
case msg, ok := <-ch:
|
||||
if !ok {
|
||||
|
||||
@@ -66,12 +66,12 @@ func (s *SocketStreamingServer) handleConnection(conn net.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
outCh, err := s.manager.ConnectStream(streamUUID)
|
||||
outCh, err := s.manager.ConnectClientStream(streamUUID)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(conn, "Failed to connect to stream: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer s.manager.DisconnectStream(streamUUID)
|
||||
defer s.manager.DisconnectClientStream(streamUUID)
|
||||
|
||||
writer := bufio.NewWriterSize(conn, 256*1024)
|
||||
defer func(w *bufio.Writer) {
|
||||
|
||||
1
services/data_service/internal/worker/stateful.go
Normal file
1
services/data_service/internal/worker/stateful.go
Normal file
@@ -0,0 +1 @@
|
||||
package worker
|
||||
1
services/data_service/internal/worker/stateless.go
Normal file
1
services/data_service/internal/worker/stateless.go
Normal file
@@ -0,0 +1 @@
|
||||
package worker
|
||||
Reference in New Issue
Block a user