From 3f8befe850f5e7ce39379b7e5264eb1b9579f419 Mon Sep 17 00:00:00 2001 From: WEIZIBIN Date: Fri, 30 Aug 2019 11:45:31 +0800 Subject: [PATCH] unregister fast --- .../com/xxl/job/admin/dao/XxlJobGroupDao.java | 4 ++ .../job/admin/service/impl/AdminBizImpl.java | 40 ++++++++++++++++++- .../mybatis-mapper/XxlJobGroupMapper.xml | 13 ++++++ .../xxl/job/core/executor/XxlJobExecutor.java | 6 +-- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java index 35f3cd3c..ddafaa8b 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java @@ -16,6 +16,10 @@ public interface XxlJobGroupDao { public List findByAddressType(@Param("addressType") int addressType); + public List findAutoRegisterGroupByAppName(@Param("appName") String appName); + + public int updateAddressListById(@Param("id") int id, @Param("addressList") String addressList); + public int save(XxlJobGroup xxlJobGroup); public int update(XxlJobGroup xxlJobGroup); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java index 270a78cd..1be9a0bc 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java @@ -1,10 +1,12 @@ package com.xxl.job.admin.service.impl; +import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; +import com.xxl.job.admin.dao.XxlJobGroupDao; import com.xxl.job.admin.dao.XxlJobInfoDao; import com.xxl.job.admin.dao.XxlJobLogDao; import com.xxl.job.admin.dao.XxlJobRegistryDao; @@ -16,6 +18,8 @@ import com.xxl.job.core.handler.IJobHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.text.MessageFormat; @@ -35,6 +39,8 @@ public class AdminBizImpl implements AdminBiz { private XxlJobInfoDao xxlJobInfoDao; @Resource private XxlJobRegistryDao xxlJobRegistryDao; + @Resource + private XxlJobGroupDao xxlJobGroupDao; @Override @@ -132,8 +138,40 @@ public class AdminBizImpl implements AdminBiz { @Override public ReturnT registryRemove(RegistryParam registryParam) { - xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); + int ret = xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); + if (ret == 1) { + List autoRegisterGroups = xxlJobGroupDao.findAutoRegisterGroupByAppName(registryParam.getRegistryKey()); + removeRegisterFromGroups(autoRegisterGroups, registryParam.getRegistryValue()); + } return ReturnT.SUCCESS; } + private void removeRegisterFromGroups(List groups, String address) { + if (StringUtils.isEmpty(address)) { + return; + } + if (CollectionUtils.isEmpty(groups)) { + return; + } + + for (XxlJobGroup group : groups) { + List addressList = group.getRegistryList(); + if (addressList == null) { + continue; + } + if (!addressList.contains(address)) { + continue; + } + + addressList.remove(address); + String newAddressListStr = StringUtils.collectionToCommaDelimitedString(addressList); + String oldAddressListStr = group.getAddressList(); + int update = xxlJobGroupDao.updateAddressListById(group.getId(), newAddressListStr); + if (logger.isDebugEnabled()) { + logger.debug("update group name [{}] title [{}] old address list [{}] new address list [{}] update result [{}]", + group.getAppName(), group.getTitle(), oldAddressListStr, newAddressListStr, update); + } + } + } + } diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml index 561c6618..0f588e68 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml @@ -27,6 +27,13 @@ ORDER BY t.order ASC + +