TASK:generate 取消generate
This commit is contained in:
@@ -46,6 +46,7 @@ public class AsyncCallerUtil {
|
||||
log.info("===============持续等待===============");
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
|
||||
log.info("阻塞等待结果...");
|
||||
// 阻塞,等待结果
|
||||
List<String> result = generateResult.get();
|
||||
// 取消定时任务
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user