Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayyush committed Sep 9, 2021
1 parent 0e80e19 commit 5e12473
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions server/controllers/logstreaming_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ func (j *LogStreamingController) GetLogStreamWS(w http.ResponseWriter, r *http.R

// Buffer size set to 1000 to ensure messages get queued (upto 1000) if the receiverCh is not ready to
// receive messages before the channel is closed and resources cleaned up.
receiverChan := make(chan string, 1000)
j.WebsocketHandler.SetCloseHandler(c, receiverChan)
receiver := make(chan string, 1000)
j.WebsocketHandler.SetCloseHandler(c, receiver)

// Add a reader goroutine to listen for socket.close() events.
go j.WebsocketHandler.SetReadHandler(c)

pull := pullInfo.String()
err = j.ProjectCommandOutputHandler.Receive(pull, receiverChan, func(msg string) error {
err = j.ProjectCommandOutputHandler.Receive(pull, receiver, func(msg string) error {
if err := c.WriteMessage(websocket.BinaryMessage, []byte(msg+"\r\n\t")); err != nil {
j.Logger.Warn("Failed to write ws message: %s", err)
return err
Expand Down
10 changes: 5 additions & 5 deletions server/handlers/project_command_output_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ProjectCommandOutputHandler interface {
Clear(ctx models.ProjectCommandContext)

// Receive will create a channel for projectPullInfo and run a callback function argument when the new channel receives a message.
Receive(projectInfo string, ch chan string, callback func(msg string) error) error
Receive(projectInfo string, receiver chan string, callback func(msg string) error) error

// Listens for msg from channel
Handle()
Expand All @@ -53,14 +53,14 @@ func (p *DefaultProjectCommandOutputHandler) Send(ctx models.ProjectCommandConte
}
}

func (p *DefaultProjectCommandOutputHandler) Receive(projectInfo string, receiverCh chan string, callback func(msg string) error) error {
func (p *DefaultProjectCommandOutputHandler) Receive(projectInfo string, receiver chan string, callback func(msg string) error) error {

// Avoid deadlock when projectOutputBuffer size is greater than the channel (currently set to 1000)
// Running this as a goroutine allows for the channel to be read in callback
go p.addChan(receiverCh, projectInfo)
defer p.cleanUp(projectInfo, receiverCh)
go p.addChan(receiver, projectInfo)
defer p.cleanUp(projectInfo, receiver)

for msg := range receiverCh {
for msg := range receiver {
if err := callback(msg); err != nil {
return err
}
Expand Down

0 comments on commit 5e12473

Please sign in to comment.