Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes #767
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin committed Mar 15, 2016
1 parent bfd3bc2 commit 77669db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions mgmt/rest/client/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ func (c *Client) WatchTask(id string) *WatchTasksResult {
return
default:
line, _ := reader.ReadBytes('\n')
sline := string(line)
if sline == "" || sline == "\n" {
continue
}
if strings.HasPrefix(sline, "data:") {
sline = strings.TrimPrefix(sline, "data:")
line = []byte(sline)
}
ste := &rbody.StreamedTaskEvent{}
err := json.Unmarshal(line, ste)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions mgmt/rest/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *Server) watchTask(w http.ResponseWriter, r *http.Request, p httprouter.
EventType: rbody.TaskWatchStreamOpen,
Message: "Stream opened",
}
fmt.Fprintf(w, "%s\n", so.ToJSON())
fmt.Fprintf(w, "data: %s\n\n", so.ToJSON())
flusher.Flush()

// Get a channel for if the client notifies us it is closing the connection
Expand All @@ -203,10 +203,10 @@ func (s *Server) watchTask(w http.ResponseWriter, r *http.Request, p httprouter.
case rbody.TaskWatchMetricEvent, rbody.TaskWatchTaskStarted:
// The client can decide to stop receiving on the stream on Task Stopped.
// We write the event to the buffer
fmt.Fprintf(w, "%s\n", e.ToJSON())
fmt.Fprintf(w, "data: %s\n\n", e.ToJSON())
case rbody.TaskWatchTaskDisabled, rbody.TaskWatchTaskStopped:
// A disabled task should end the streaming and close the connection
fmt.Fprintf(w, "%s\n", e.ToJSON())
fmt.Fprintf(w, "data: %s\n\n", e.ToJSON())
// Flush since we are sending nothing new
flusher.Flush()
// Close out watcher removing it from the scheduler
Expand Down

0 comments on commit 77669db

Please sign in to comment.