From fb47a28bc95aaa2acb4fbff22ac0a649bd1fe6ee Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 15 Apr 2024 20:58:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E7=AC=AC=E4=B8=89=E6=96=B9=E5=90=8E=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E9=A1=B9=E7=9B=AE=E5=90=8C=E6=AD=A5=E5=A4=9A=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --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 --- .../io/metersphere/bug/job/BugSyncJob.java | 39 +++++++++++++------ .../bug/service/BugSyncExtraService.java | 8 ++-- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java index 6f8e675050..896f073434 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java @@ -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,19 +52,31 @@ public class BugSyncJob extends BaseScheduleJob { return; } LogUtils.info("bug sync job start......"); - if (licenseService == null) { - LogUtils.info("license is null, sync remain bug"); - bugSyncService.syncPlatformBugBySchedule(resourceId, userId); - } else { - LicenseDTO licenseDTO = licenseService.validate(); - if (licenseDTO != null && licenseDTO.getLicense() != null - && StringUtils.equals(licenseDTO.getStatus(), "valid")) { - LogUtils.info("license is valid, sync all bug"); - xpackBugService.syncPlatformBugsBySchedule(resourceId, userId); - } else { - LogUtils.info("license is invalid, sync remain bug"); - bugSyncService.syncPlatformBugBySchedule(resourceId, userId); + // 获取当前项目同步缺陷唯一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); + } else { + LicenseDTO licenseDTO = licenseService.validate(); + if (licenseDTO != null && licenseDTO.getLicense() != null + && StringUtils.equals(licenseDTO.getStatus(), "valid")) { + LogUtils.info("license is valid, sync all bug"); + xpackBugService.syncPlatformBugsBySchedule(resourceId, userId); + } else { + LogUtils.info("license is invalid, sync remain bug"); + bugSyncService.syncPlatformBugBySchedule(resourceId, userId); + } + } + bugSyncExtraService.deleteSyncKey(resourceId); } + } catch (Exception e) { + bugSyncExtraService.deleteSyncKey(resourceId); + LogUtils.error(e.getMessage()); } LogUtils.info("bug sync job end......"); } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncExtraService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncExtraService.java index 49cc49e617..2ff64035a9 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncExtraService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncExtraService.java @@ -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); } /**