diff --git a/pkg/koyeb/utils.go b/pkg/koyeb/utils.go index d3540c78..89e07e13 100644 --- a/pkg/koyeb/utils.go +++ b/pkg/koyeb/utils.go @@ -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) }