TASK:generate 取消generate

This commit is contained in:
2024-01-24 16:57:53 +08:00
parent 1d2cb17d54
commit 65bed9dada
2 changed files with 15 additions and 11 deletions

View File

@@ -56,8 +56,6 @@ public class PythonService {
private String accessPythonIp;
@Value("${access.python.port:''}")
private String accessPythonPort;
@Value("${access.generate.port:''}")
private String accessGeneratePort;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@@ -2427,27 +2425,32 @@ public class PythonService {
throw new BusinessException("cloth-classification.interface.exception");
}
public void cancelGenerateTask(String taskId){
public Boolean cancelGenerateTask(String taskId){
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
HttpUrl.Builder builder = HttpUrl.parse(accessPythonIp + ":" + accessGeneratePort + "/cancel_task").newBuilder();
builder.addQueryParameter("task_id",taskId);
String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId + "/";
Request request = new Request.Builder()
.url(builder.build().toString())
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.url(url)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
// .addHeader("Content-Type", "application/json")
.build();
Response response;
try {
log.info("getGenerateResult请求入参content###{}", taskId);
client.newCall(request).execute();
log.info("cancelGenerateTask请求入参content###{}", taskId);
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##getGenerateResult异常###{}", ExceptionUtil.getThrowableList(ioException));
log.error("PythonService##cancelGenerateTask异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("generate.interface.error");
}
if (response.code() != HttpURLConnection.HTTP_OK){
return Boolean.FALSE;
}
return Boolean.TRUE;
}
}