fix(缺陷管理): 对接第三方后同一项目同步多次

--bug=1039294 --user=宋昌昌 【缺陷管理】JIRA/禅道项目管理同步缺陷-修改项目key后全量同步未生效 https://www.tapd.cn/55049933/s/1497744
--bug=1039264 --user=宋昌昌 【缺陷管理】JIRA全量同步-同步到ms缺陷和JIRA平台数据不一致 https://www.tapd.cn/55049933/s/1497344
--bug=1039382 --user=宋昌昌 【项目管理】应用管理-缺陷管理-配置JIRA后,同步缺陷增量频率是1小时,同步失败 https://www.tapd.cn/55049933/s/1497721
This commit is contained in:
song-cc-rock 2024-04-15 20:58:30 +08:00 committed by Craftsman
parent 53f2c736f7
commit fb47a28bc9
2 changed files with 31 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.bug.job;
import io.metersphere.bug.service.BugSyncExtraService;
import io.metersphere.bug.service.BugSyncService;
import io.metersphere.bug.service.XpackBugService;
import io.metersphere.project.service.ProjectApplicationService;
@ -23,12 +24,14 @@ public class BugSyncJob extends BaseScheduleJob {
private final LicenseService licenseService;
private final BugSyncService bugSyncService;
private final XpackBugService xpackBugService;
private final BugSyncExtraService bugSyncExtraService;
private final ProjectApplicationService projectApplicationService;
public BugSyncJob() {
licenseService = CommonBeanFactory.getBean(LicenseService.class);
xpackBugService = CommonBeanFactory.getBean(XpackBugService.class);
bugSyncService = CommonBeanFactory.getBean(BugSyncService.class);
bugSyncExtraService = CommonBeanFactory.getBean(BugSyncExtraService.class);
projectApplicationService = CommonBeanFactory.getBean(ProjectApplicationService.class);
}
@ -49,6 +52,12 @@ public class BugSyncJob extends BaseScheduleJob {
return;
}
LogUtils.info("bug sync job start......");
// 获取当前项目同步缺陷唯一Key
try{
String syncValue = bugSyncExtraService.getSyncKey(resourceId);
if (StringUtils.isEmpty(syncValue)) {
// 不存在, 设置保证唯一性, 并开始同步
bugSyncExtraService.setSyncKey(resourceId);
if (licenseService == null) {
LogUtils.info("license is null, sync remain bug");
bugSyncService.syncPlatformBugBySchedule(resourceId, userId);
@ -63,6 +72,12 @@ public class BugSyncJob extends BaseScheduleJob {
bugSyncService.syncPlatformBugBySchedule(resourceId, userId);
}
}
bugSyncExtraService.deleteSyncKey(resourceId);
}
} catch (Exception e) {
bugSyncExtraService.deleteSyncKey(resourceId);
LogUtils.error(e.getMessage());
}
LogUtils.info("bug sync job end......");
}

View File

@ -15,7 +15,7 @@ public class BugSyncExtraService {
@Resource
private StringRedisTemplate stringRedisTemplate;
private static final String SYNC_THIRD_PARTY_ISSUES_KEY = "MS:BUG:SYNC";
private static final String SYNC_THIRD_PARTY_BUG_KEY = "MS:BUG:SYNC";
private static final String SYNC_THIRD_PARTY_ISSUES_ERROR_KEY = "MS:BUG:SYNC:ERROR";
/**
@ -23,7 +23,7 @@ public class BugSyncExtraService {
* @param projectId 项目ID
*/
public void setSyncKey(String projectId) {
stringRedisTemplate.opsForValue().set(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId, UUID.randomUUID().toString(), 60 * 10L, TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(SYNC_THIRD_PARTY_BUG_KEY + ":" + projectId, UUID.randomUUID().toString(), 60 * 10L, TimeUnit.SECONDS);
}
/**
@ -31,7 +31,7 @@ public class BugSyncExtraService {
* @param projectId 项目ID
*/
public String getSyncKey(String projectId) {
return stringRedisTemplate.opsForValue().get(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId);
return stringRedisTemplate.opsForValue().get(SYNC_THIRD_PARTY_BUG_KEY + ":" + projectId);
}
/**
@ -39,7 +39,7 @@ public class BugSyncExtraService {
* @param projectId 项目ID
*/
public void deleteSyncKey(String projectId) {
stringRedisTemplate.delete(SYNC_THIRD_PARTY_ISSUES_KEY + ":" + projectId);
stringRedisTemplate.delete(SYNC_THIRD_PARTY_BUG_KEY + ":" + projectId);
}
/**