TASK:generate 取消generate
This commit is contained in:
@@ -46,6 +46,7 @@ public class AsyncCallerUtil {
|
|||||||
log.info("===============持续等待===============");
|
log.info("===============持续等待===============");
|
||||||
}, 10, 10, TimeUnit.SECONDS);
|
}, 10, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
log.info("阻塞等待结果...");
|
||||||
// 阻塞,等待结果
|
// 阻塞,等待结果
|
||||||
List<String> result = generateResult.get();
|
List<String> result = generateResult.get();
|
||||||
// 取消定时任务
|
// 取消定时任务
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ public class PythonService {
|
|||||||
private String accessPythonIp;
|
private String accessPythonIp;
|
||||||
@Value("${access.python.port:''}")
|
@Value("${access.python.port:''}")
|
||||||
private String accessPythonPort;
|
private String accessPythonPort;
|
||||||
@Value("${access.generate.port:''}")
|
|
||||||
private String accessGeneratePort;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PythonTAllInfoService pythonTAllInfoService;
|
private PythonTAllInfoService pythonTAllInfoService;
|
||||||
@@ -2427,27 +2425,32 @@ public class PythonService {
|
|||||||
throw new BusinessException("cloth-classification.interface.exception");
|
throw new BusinessException("cloth-classification.interface.exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelGenerateTask(String taskId){
|
public Boolean cancelGenerateTask(String taskId){
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
.connectTimeout(30, TimeUnit.SECONDS)
|
.connectTimeout(30, TimeUnit.SECONDS)
|
||||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||||
.build();
|
.build();
|
||||||
HttpUrl.Builder builder = HttpUrl.parse(accessPythonIp + ":" + accessGeneratePort + "/cancel_task").newBuilder();
|
String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId + "/";
|
||||||
builder.addQueryParameter("task_id",taskId);
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(builder.build().toString())
|
.url(url)
|
||||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||||
.addHeader("Content-Type", "application/json")
|
// .addHeader("Content-Type", "application/json")
|
||||||
.build();
|
.build();
|
||||||
|
Response response;
|
||||||
try {
|
try {
|
||||||
log.info("getGenerateResult请求入参content###{}", taskId);
|
log.info("cancelGenerateTask请求入参content###{}", taskId);
|
||||||
client.newCall(request).execute();
|
response = client.newCall(request).execute();
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
log.error("PythonService##getGenerateResult异常###{}", ExceptionUtil.getThrowableList(ioException));
|
log.error("PythonService##cancelGenerateTask异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
throw new BusinessException("generate.interface.error");
|
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