From 538b5f5d3ccba6cfd1fd58a80850ef5d0de4dd04 Mon Sep 17 00:00:00 2001 From: Lcp <2767378157@qq.com> Date: Sat, 14 Sep 2024 22:10:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E3=80=91=E5=A4=9A=E7=A7=9F=E6=88=B7=E4=B8=8B=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BB=93=E6=9E=9C=E5=A4=84=E7=90=86=E9=83=BD?= =?UTF-8?q?=E4=B8=BA=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/tenant/core/job/TenantJobAspect.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java index e375f9c33..61efa15a5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java @@ -42,15 +42,16 @@ public class TenantJobAspect { } // 逐个租户,执行 Job - Map results = new ConcurrentHashMap<>(); + Map success = new ConcurrentHashMap<>(); + Map fail = new ConcurrentHashMap<>(); tenantIds.parallelStream().forEach(tenantId -> { // TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况 TenantUtils.execute(tenantId, () -> { try { Object result = joinPoint.proceed(); - results.put(tenantId, StrUtil.toStringOrNull(result)); + success.put(tenantId, StrUtil.toStringOrNull(result)); } catch (Throwable e) { - results.put(tenantId, ExceptionUtil.getRootCauseMessage(e)); + fail.put(tenantId, ExceptionUtil.getRootCauseMessage(e)); // 打印异常 XxlJobHelper.log(StrUtil.format("[多租户({}) 执行任务({}),发生异常:{}]", tenantId, joinPoint.getSignature(), ExceptionUtils.getStackTrace(e))); @@ -58,8 +59,11 @@ public class TenantJobAspect { }); }); // 如果 results 非空,说明发生了异常,标记 XXL-Job 执行失败 - if (CollUtil.isNotEmpty(results)) { - XxlJobHelper.handleFail(JsonUtils.toJsonString(results)); + if (CollUtil.isNotEmpty(fail)) { + XxlJobHelper.handleFail(JsonUtils.toJsonString(fail)); + } + else { + XxlJobHelper.handleSuccess(JsonUtils.toJsonString(success)); } }