【功能修复】Job 组件:修复多租户下,XXL-Job 无法传参的问题

master-jdk17
YunaiV 2024-12-01 16:37:21 +08:00
parent 50e47434bb
commit ab5c790b3d
1 changed files with 4 additions and 0 deletions

View File

@ -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<Long, String> 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) {