|
|
|
@@ -636,3 +636,44 @@ sendjob: |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |
|
|
|
|
|
|
|
func StopTrainJob(jobID, versionID string) (*models.TrainJobResult, error) { |
|
|
|
checkSetting() |
|
|
|
client := getRestyClient() |
|
|
|
var result models.TrainJobResult |
|
|
|
|
|
|
|
retry := 0 |
|
|
|
|
|
|
|
sendjob: |
|
|
|
res, err := client.R(). |
|
|
|
SetAuthToken(TOKEN). |
|
|
|
SetResult(&result). |
|
|
|
Post(HOST + "/v1/" + setting.ProjectID + urlTrainJob + "/" + jobID + "/versions/" + versionID + "/stop") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return &result, fmt.Errorf("resty StopTrainJob: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { |
|
|
|
retry++ |
|
|
|
_ = getToken() |
|
|
|
goto sendjob |
|
|
|
} |
|
|
|
|
|
|
|
if res.StatusCode() != http.StatusOK { |
|
|
|
var temp models.ErrorResult |
|
|
|
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { |
|
|
|
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) |
|
|
|
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) |
|
|
|
} |
|
|
|
log.Error("StopTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
return &result, fmt.Errorf("StopTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
if !result.IsSuccess { |
|
|
|
log.Error("StopTrainJob(%s) failed", jobID) |
|
|
|
return &result, fmt.Errorf("停止训练作业失败:%s", result.ErrorMsg) |
|
|
|
} |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |