Commit d3452f73 authored by duanjinfei's avatar duanjinfei

update check container healthy

No related merge requests found
......@@ -431,28 +431,28 @@ func (op *TaskOp) getFileCache(respStr string, dockerOp *operate.DockerOp) (stri
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)
healthyCheckResp, err := op.httpClient.Get(healthCheckUrl)
if err != nil {
log.Errorf("Request container healthy failed: %s", err.Error())
return fmt.Errorf("%s-%s", "The container is not ready", err)
log.Warn("Request container healthy failed: %s", err.Error())
return false, nil
}
if healthyCheckResp.StatusCode == http.StatusNotFound {
return nil
return true, nil
}
body, err := io.ReadAll(healthyCheckResp.Body)
m := &models.HealthyCheck{}
err = json.Unmarshal(body, m)
if err != nil {
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 {
log.Errorf("The container is not ready")
return fmt.Errorf("%s", "The container is not ready")
log.Warn("The container is not ready")
return false, nil
}
return nil
return true, nil
}
func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) error {
......@@ -476,9 +476,11 @@ func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) erro
continue
}
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")
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)
......
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