fix(测试跟踪): 同步缺陷管理缺少并行控制

--bug=1014127 --user=宋昌昌 【测试跟踪】同步第三方平台缺陷缺少并行限制 https://www.tapd.cn/55049933/s/1186746
This commit is contained in:
song-cc-rock 2022-06-20 15:55:07 +08:00 committed by jianxing
parent e4b938788e
commit 9e896cb0ce
1 changed files with 13 additions and 0 deletions

View File

@ -40,12 +40,14 @@ import io.metersphere.track.request.testcase.TestCaseBatchRequest;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -80,6 +82,10 @@ public class IssuesService {
private IssueFollowMapper issueFollowMapper; private IssueFollowMapper issueFollowMapper;
@Resource @Resource
private TestPlanTestCaseMapper testPlanTestCaseMapper; private TestPlanTestCaseMapper testPlanTestCaseMapper;
@Resource
StringRedisTemplate stringRedisTemplate;
private static final String SYNC_THIRD_PARTY_ISSUES_KEY = "ISSUE:SYNC";
public void testAuth(String workspaceId, String platform) { public void testAuth(String workspaceId, String platform) {
IssuesRequest issuesRequest = new IssuesRequest(); IssuesRequest issuesRequest = new IssuesRequest();
@ -487,6 +493,12 @@ public class IssuesService {
public void syncThirdPartyIssues(String projectId) { public void syncThirdPartyIssues(String projectId) {
if (StringUtils.isNotBlank(projectId)) { if (StringUtils.isNotBlank(projectId)) {
String syncValue = stringRedisTemplate.opsForValue().get(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId);
if (StringUtils.isNotEmpty(syncValue)) {
MSException.throwException("当前项目正在同步缺陷, 请稍等");
}
stringRedisTemplate.opsForValue().set(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId,
UUID.randomUUID().toString(), 60 * 10, TimeUnit.SECONDS);
Project project = projectService.getProjectById(projectId); Project project = projectService.getProjectById(projectId);
List<IssuesDao> issues = extIssuesMapper.getIssueForSync(projectId); List<IssuesDao> issues = extIssuesMapper.getIssueForSync(projectId);
@ -538,6 +550,7 @@ public class IssuesService {
LogUtil.error(e); LogUtil.error(e);
} }
} }
stringRedisTemplate.delete(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId);
} }
} }