Skip to content

Commit

Permalink
Add log in case of deployment error / unhealthy
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardb committed Feb 24, 2022
1 parent 696310e commit 0be3b36
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions pkg/koyeb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,32 @@ func loadYaml(file string) (string, error) {
}

func watchDeployment(h *ServiceHandler, deploymentId string) {
numAttemptsOnUnhealthy := 12
retryCount := 0
retryInterval := 5
now := time.Now()
prevStatus := koyeb.DEPLOYMENTSTATUS_PENDING
retryInterval := 5 * time.Second
timeoutAt := time.Minute * 10

for {
for time.Since(now) < timeoutAt {
res, resp, err := h.client.DeploymentsApi.GetDeployment(h.ctx, deploymentId).Execute()
if err != nil {
fatalApiError(err, resp)
}
currentStatus := res.Deployment.GetStatus()

log.Infof("Service deployment in progress. Deployment status is %s. Next update in %d seconds.", currentStatus, retryInterval)
log.Infof("Service deployment in progress. Deployment status is %q. Next update in %s.", currentStatus, retryInterval)

if currentStatus == koyeb.DEPLOYMENTSTATUS_ERROR || currentStatus == koyeb.DEPLOYMENTSTATUS_HEALTHY || retryCount >= numAttemptsOnUnhealthy {
break
} else if currentStatus == koyeb.DEPLOYMENTSTATUS_UNHEALTHY {
retryCount += 1
retryInterval = 10
time.Sleep(time.Duration(retryInterval) * time.Second)
} else {
time.Sleep(time.Duration(retryInterval) * time.Second)
if currentStatus == koyeb.DEPLOYMENTSTATUS_ERROR || currentStatus == koyeb.DEPLOYMENTSTATUS_HEALTHY {
if currentStatus == koyeb.DEPLOYMENTSTATUS_ERROR {
log.Infof("Service deployment failed. Please check the logs.")
}
return
} else if currentStatus == koyeb.DEPLOYMENTSTATUS_UNHEALTHY && prevStatus != koyeb.DEPLOYMENTSTATUS_UNHEALTHY {
timeoutAt = time.Minute * 5
now = time.Now()
}
time.Sleep(retryInterval)
prevStatus = currentStatus
}

log.Infof("Service deployment didn't pass health checks. Last status was %q", prevStatus)
}

0 comments on commit 0be3b36

Please sign in to comment.