Commit d3452f73 authored by duanjinfei's avatar duanjinfei

update check container healthy

parent 5a300b51
...@@ -431,28 +431,28 @@ func (op *TaskOp) getFileCache(respStr string, dockerOp *operate.DockerOp) (stri ...@@ -431,28 +431,28 @@ func (op *TaskOp) getFileCache(respStr string, dockerOp *operate.DockerOp) (stri
return "", nil return "", nil
} }
func (op *TaskOp) checkContainerHealthy(internalIp string, internalPort uint16) error { func (op *TaskOp) checkContainerHealthy(internalIp string, internalPort uint16) (bool, error) {
healthCheckUrl := fmt.Sprintf("http://%s:%d%s", internalIp, internalPort, models.HealthCheckAPI) healthCheckUrl := fmt.Sprintf("http://%s:%d%s", internalIp, internalPort, models.HealthCheckAPI)
healthyCheckResp, err := op.httpClient.Get(healthCheckUrl) healthyCheckResp, err := op.httpClient.Get(healthCheckUrl)
if err != nil { if err != nil {
log.Errorf("Request container healthy failed: %s", err.Error()) log.Warn("Request container healthy failed: %s", err.Error())
return fmt.Errorf("%s-%s", "The container is not ready", err) return false, nil
} }
if healthyCheckResp.StatusCode == http.StatusNotFound { if healthyCheckResp.StatusCode == http.StatusNotFound {
return nil return true, nil
} }
body, err := io.ReadAll(healthyCheckResp.Body) body, err := io.ReadAll(healthyCheckResp.Body)
m := &models.HealthyCheck{} m := &models.HealthyCheck{}
err = json.Unmarshal(body, m) err = json.Unmarshal(body, m)
if err != nil { if err != nil {
log.Errorf("Json unmarshal container healthy body failed: %s", err.Error()) log.Errorf("Json unmarshal container healthy body failed: %s", err.Error())
return fmt.Errorf("%s,%s", "Json unmarshal container healthy body failed", err.Error()) return false, fmt.Errorf("%s,%s", "Json unmarshal container healthy body failed", err.Error())
} }
if m.Status != models.READY { if m.Status != models.READY {
log.Errorf("The container is not ready") log.Warn("The container is not ready")
return fmt.Errorf("%s", "The container is not ready") return false, nil
} }
return nil return true, nil
} }
func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) error { func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) error {
...@@ -476,9 +476,11 @@ func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) erro ...@@ -476,9 +476,11 @@ func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) erro
continue continue
} }
if isMatch := strings.HasPrefix(op.taskCmd.ImageName, models.ReplicateImageNameSuffix); isMatch { if isMatch := strings.HasPrefix(op.taskCmd.ImageName, models.ReplicateImageNameSuffix); isMatch {
if err := op.checkContainerHealthy(internalIp, internalPort); err != nil { if isReqSuccess, err := op.checkContainerHealthy(internalIp, internalPort); err != nil {
log.WithField("err", err).Errorf("check container healthy failed") log.WithField("err", err).Errorf("check container healthy failed")
return fmt.Errorf("%s-%s", "check container healthy failed", err.Error()) return fmt.Errorf("%s-%s", "check container healthy failed", err.Error())
} else if !isReqSuccess {
continue
} }
} }
op.taskCmd.ApiUrl = fmt.Sprintf("http://%s:%d%s", internalIp, internalPort, op.taskCmd.ApiUrl) op.taskCmd.ApiUrl = fmt.Sprintf("http://%s:%d%s", internalIp, internalPort, op.taskCmd.ApiUrl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment