From ab5c790b3d559a72f2bf2ef7557303c25b30edd5 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 1 Dec 2024 16:37:21 +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=91Job=20=E7=BB=84=E4=BB=B6=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E4=B8=8B=EF=BC=8CXXL-Job=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E4=BC=A0=E5=8F=82=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/framework/tenant/core/job/TenantJobAspect.java | 4 ++++ 1 file changed, 4 insertions(+) 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 135b3cc3f..07bbdee59 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 @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; +import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.context.XxlJobHelper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -45,10 +46,13 @@ public class TenantJobAspect { // 逐个租户,执行 Job Map results = new ConcurrentHashMap<>(); AtomicBoolean success = new AtomicBoolean(true); // 标记,是否存在失败的情况 + XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); // XXL-Job 上下文 tenantIds.parallelStream().forEach(tenantId -> { // TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况 TenantUtils.execute(tenantId, () -> { try { + XxlJobContext.setXxlJobContext(xxlJobContext); + // 执行 Job Object result = joinPoint.proceed(); results.put(tenantId, StrUtil.toStringOrEmpty(result)); } catch (Throwable e) {