Skip to content

Commit

Permalink
Since multiple deployment can be run on parallel and the new event is…
Browse files Browse the repository at this point in the history
… not always fetched, ensure logs are streamed after 'scalingo deploy .jar/war

Fixes #359
  • Loading branch information
Soulou committed Jun 5, 2018
1 parent 1ffb8cb commit 3ecd062
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions deployments/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ func Stream(opts *StreamOpts) error {
}

var event deployEvent
var currentDeployment *scalingo.Deployment
oldStatus := ""
currentDeployment := &scalingo.Deployment{
ID: opts.DeploymentID,
}
anyDeployment := currentDeployment.ID == ""
statuses := map[string]string{}

for {
err := websocket.JSON.Receive(conn, &event)
if err != nil {
Expand All @@ -72,7 +76,7 @@ func Stream(opts *StreamOpts) error {
case "ping":
case "log":
// If we stream logs of a specific deployment and this event is not about this one
if opts.DeploymentID != "" && (currentDeployment == nil || opts.DeploymentID != currentDeployment.ID) {
if !anyDeployment && event.ID != currentDeployment.ID {
continue
}
var logData logData
Expand All @@ -84,7 +88,7 @@ func Stream(opts *StreamOpts) error {
fmt.Println("[LOG] " + strings.TrimSpace(logData.Content))
case "status":
// If we stream logs of a specific deployment and this event is not about this one
if opts.DeploymentID != "" && (currentDeployment == nil || opts.DeploymentID != currentDeployment.ID) {
if !anyDeployment && event.ID != currentDeployment.ID {
continue
}
var statusData statusData
Expand All @@ -93,25 +97,32 @@ func Stream(opts *StreamOpts) error {
config.C.Logger.Println(err)
continue
}
if oldStatus == "" {
if statuses[event.ID] == "" {
fmt.Println("[STATUS] New status: " + statusData.Content)
} else {
fmt.Println("[STATUS] New status: " + oldStatus + " → " + statusData.Content)
fmt.Println("[STATUS] New status: " + statuses[event.ID] + " → " + statusData.Content)
}
oldStatus = statusData.Content
if opts.DeploymentID != "" && scalingo.IsFinishedString(scalingo.DeploymentStatus(statusData.Content)) {
statuses[event.ID] = statusData.Content

if !anyDeployment && scalingo.IsFinishedString(scalingo.DeploymentStatus(statusData.Content)) {
return nil
}
case "new":
oldStatus = ""
var newData map[string]*scalingo.Deployment
err := json.Unmarshal(event.Data, &newData)
if err != nil {
config.C.Logger.Println(err)
continue
}
currentDeployment = newData["deployment"]
fmt.Println("[NEW] New deploy: " + currentDeployment.ID + " from " + currentDeployment.User.Username)
newDeployment := newData["deployment"]

if newDeployment.ID == currentDeployment.ID {
currentDeployment = newDeployment
}

if anyDeployment || newDeployment.ID == currentDeployment.ID {
fmt.Println("[NEW] New deploy: " + newDeployment.ID + " from " + newDeployment.User.Username)
}
}
}
}
Expand Down

0 comments on commit 3ecd062

Please sign in to comment.