fix(测试跟踪): 项目数量较大时定时同步缺陷时数据库压力异常
--bug=1014751 --user=陈建星 【测试跟踪】定时同步缺陷时数据库压力异常 https://www.tapd.cn/55049933/s/1198207
This commit is contained in:
parent
725d4aa1a9
commit
0a2f0d090a
|
@ -22,7 +22,7 @@ public interface ExtIssuesMapper {
|
|||
|
||||
Issues getNextNum(String projectId);
|
||||
|
||||
List<IssuesDao> getIssueForSync(String projectId);
|
||||
List<IssuesDao> getIssueForSync(@Param("projectId") String projectId, @Param("platform") String platform);
|
||||
|
||||
List<PlanReportIssueDTO> selectForPlanReport(String planId);
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
<select id="getIssueForSync" resultType="io.metersphere.base.domain.IssuesDao">
|
||||
select id,platform, platform_id
|
||||
from issues
|
||||
where project_id = #{projectId} and platform != 'Local' and (platform_status != 'delete' or platform_status is null);
|
||||
where project_id = #{projectId} and platform = #{platform} and (platform_status != 'delete' or platform_status is null);
|
||||
</select>
|
||||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportIssueDTO">
|
||||
select id,status,platform_status,platform from issues where resource_id = #{planId} and ( platform_status != 'delete' or platform_status is null);
|
||||
|
|
|
@ -47,4 +47,6 @@ public interface ExtProjectMapper {
|
|||
List<ProjectDTO> queryListByIds(@Param("ids") List<String> ids);
|
||||
|
||||
void updateUseDefaultCaseTemplateProject(@Param("originId") String originId,@Param("templateId") String templateId,@Param("projectId") String projectId);
|
||||
|
||||
List<String> getThirdPartProjectIds();
|
||||
}
|
||||
|
|
|
@ -307,8 +307,9 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getThirdPartProjectIds" resultType="java.lang.String">
|
||||
select id from project where platform != 'Local';
|
||||
</select>
|
||||
<insert id="setDefaultMessageTask">
|
||||
INSERT INTO message_task (id, type, event, user_id, task_type, webhook, identification, is_set, project_id,
|
||||
test_id, create_time, template)
|
||||
|
|
|
@ -2,22 +2,36 @@ package io.metersphere.job.sechedule;
|
|||
|
||||
import io.metersphere.commons.constants.ScheduleGroup;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.service.ProjectService;
|
||||
import io.metersphere.track.service.IssuesService;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IssueSyncJob extends MsScheduleJob {
|
||||
|
||||
private IssuesService issuesService;
|
||||
private ProjectService projectService;
|
||||
|
||||
public IssueSyncJob() {
|
||||
issuesService = CommonBeanFactory.getBean(IssuesService.class);
|
||||
projectService = CommonBeanFactory.getBean(ProjectService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
void businessExecute(JobExecutionContext context) {
|
||||
issuesService.syncThirdPartyIssues();
|
||||
List<String> projectIds = projectService.getThirdPartProjectIds();
|
||||
projectIds.forEach(id -> {
|
||||
try {
|
||||
// 一个项目开启一个事务,
|
||||
issuesService.syncThirdPartyIssues(id);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static JobKey getJobKey(String projectId) {
|
||||
|
|
|
@ -835,6 +835,10 @@ public class ProjectService {
|
|||
return extProjectMapper.getProjectForCustomField(workspaceId);
|
||||
}
|
||||
|
||||
public List<String> getThirdPartProjectIds() {
|
||||
return extProjectMapper.getThirdPartProjectIds();
|
||||
}
|
||||
|
||||
public Map<String, Project> queryNameByIds(List<String> ids) {
|
||||
return extProjectMapper.queryNameByIds(ids);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.IssueFollowMapper;
|
||||
import io.metersphere.base.mapper.IssuesMapper;
|
||||
import io.metersphere.base.mapper.TestCaseIssuesMapper;
|
||||
import io.metersphere.base.mapper.TestPlanTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
|
||||
import io.metersphere.commons.constants.AttachmentType;
|
||||
import io.metersphere.commons.constants.IssueRefType;
|
||||
|
@ -45,7 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
|
@ -591,7 +594,7 @@ public class IssuesService {
|
|||
}
|
||||
|
||||
public void syncThirdPartyIssues() {
|
||||
List<String> projectIds = projectService.getProjectIds();
|
||||
List<String> projectIds = projectService.getThirdPartProjectIds();
|
||||
projectIds.forEach(id -> {
|
||||
try {
|
||||
syncThirdPartyIssues(id);
|
||||
|
@ -643,59 +646,32 @@ public class IssuesService {
|
|||
if (StringUtils.isNotEmpty(syncValue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setSyncKey(projectId);
|
||||
|
||||
Project project = projectService.getProjectById(projectId);
|
||||
List<IssuesDao> issues = extIssuesMapper.getIssueForSync(projectId);
|
||||
List<IssuesDao> issues = extIssuesMapper.getIssueForSync(projectId, project.getPlatform());
|
||||
|
||||
if (CollectionUtils.isEmpty(issues)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<IssuesDao> tapdIssues = issues.stream()
|
||||
.filter(item -> item.getPlatform().equals(IssuesManagePlatform.Tapd.name()))
|
||||
.collect(Collectors.toList());
|
||||
List<IssuesDao> jiraIssues = issues.stream()
|
||||
.filter(item -> item.getPlatform().equals(IssuesManagePlatform.Jira.name()))
|
||||
.collect(Collectors.toList());
|
||||
List<IssuesDao> zentaoIssues = issues.stream()
|
||||
.filter(item -> item.getPlatform().equals(IssuesManagePlatform.Zentao.name()))
|
||||
.collect(Collectors.toList());
|
||||
List<IssuesDao> azureDevopsIssues = issues.stream()
|
||||
.filter(item -> item.getPlatform().equals(IssuesManagePlatform.AzureDevops.name()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
IssuesRequest issuesRequest = new IssuesRequest();
|
||||
issuesRequest.setProjectId(projectId);
|
||||
issuesRequest.setWorkspaceId(project.getWorkspaceId());
|
||||
if (!projectService.isThirdPartTemplate(project)) {
|
||||
String defaultCustomFields = getDefaultCustomFields(projectId);
|
||||
issuesRequest.setDefaultCustomFields(defaultCustomFields);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(tapdIssues)) {
|
||||
TapdPlatform tapdPlatform = new TapdPlatform(issuesRequest);
|
||||
syncThirdPartyIssues(tapdPlatform::syncIssues, project, tapdIssues);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(jiraIssues)) {
|
||||
JiraPlatform jiraPlatform = new JiraPlatform(issuesRequest);
|
||||
syncThirdPartyIssues(jiraPlatform::syncIssues, project, jiraIssues);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(zentaoIssues)) {
|
||||
ZentaoPlatform zentaoPlatform = new ZentaoPlatform(issuesRequest);
|
||||
syncThirdPartyIssues(zentaoPlatform::syncIssues, project, zentaoIssues);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(azureDevopsIssues)) {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Class clazz = loader.loadClass("io.metersphere.xpack.issue.azuredevops.AzureDevopsPlatform");
|
||||
Constructor cons = clazz.getDeclaredConstructor(new Class[]{IssuesRequest.class});
|
||||
AbstractIssuePlatform azureDevopsPlatform = (AbstractIssuePlatform) cons.newInstance(issuesRequest);
|
||||
syncThirdPartyIssues(azureDevopsPlatform::syncIssues, project, azureDevopsIssues);
|
||||
} catch (Throwable e) {
|
||||
LogUtil.error(e);
|
||||
try {
|
||||
if (!projectService.isThirdPartTemplate(project)) {
|
||||
String defaultCustomFields = getDefaultCustomFields(projectId);
|
||||
issuesRequest.setDefaultCustomFields(defaultCustomFields);
|
||||
}
|
||||
AbstractIssuePlatform platform = IssueFactory.createPlatform(project.getPlatform(), issuesRequest);
|
||||
syncThirdPartyIssues(platform::syncIssues, project, issues);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
deleteSyncKey(projectId);
|
||||
}
|
||||
deleteSyncKey(projectId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue