From 65bed9dada9b6d89b3fb47e4e093b869d3a433dd Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 24 Jan 2024 16:57:53 +0800 Subject: [PATCH] =?UTF-8?q?TASK:generate=20=E5=8F=96=E6=B6=88generate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/common/utils/AsyncCallerUtil.java | 1 + .../java/com/ai/da/python/PythonService.java | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/AsyncCallerUtil.java b/src/main/java/com/ai/da/common/utils/AsyncCallerUtil.java index 640880d5..7ef9e3a0 100644 --- a/src/main/java/com/ai/da/common/utils/AsyncCallerUtil.java +++ b/src/main/java/com/ai/da/common/utils/AsyncCallerUtil.java @@ -46,6 +46,7 @@ public class AsyncCallerUtil { log.info("===============持续等待==============="); }, 10, 10, TimeUnit.SECONDS); + log.info("阻塞等待结果..."); // 阻塞,等待结果 List result = generateResult.get(); // 取消定时任务 diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 292c6243..b8ecb4e2 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -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; } }