From ba82146c25fbb04cc4e6febe65d36c776e07cd81 Mon Sep 17 00:00:00 2001 From: carlyin Date: Wed, 4 Dec 2024 11:30:21 +0800 Subject: [PATCH] =?UTF-8?q?pref=EF=BC=9A=E7=A0=94=E5=8F=91=E5=95=86?= =?UTF-8?q?=E5=BA=97=E9=80=9A=E7=94=A8=E5=8C=96=E6=8E=A5=E5=8F=A3=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E4=BC=98=E5=8C=96=20#11049?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/StoreReleaseServiceImpl.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt index aff14ca43e0..303082d47a2 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt @@ -33,6 +33,8 @@ import com.tencent.devops.common.api.constant.KEY_REPOSITORY_HASH_ID import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.redis.RedisLock +import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.SpringContextUtil import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig @@ -95,6 +97,7 @@ import java.time.LocalDateTime class StoreReleaseServiceImpl @Autowired constructor( private val client: Client, private val dslContext: DSLContext, + private val redisOperation: RedisOperation, private val storeBaseQueryDao: StoreBaseQueryDao, private val storeBaseManageDao: StoreBaseManageDao, private val storeBaseFeatureExtQueryDao: StoreBaseFeatureExtQueryDao, @@ -502,19 +505,25 @@ class StoreReleaseServiceImpl @Autowired constructor( StoreReleaseSpecBusService::class.java, StoreUtils.getReleaseSpecBusServiceBeanName(storeType) ) val status = storeReleaseSpecBusService.getStoreRunPipelineStatus(startFlag = false) - status?.let { - checkStoreVersionOptRight(userId, storeId, status) + val lock = RedisLock(redisOperation, "store:$storeId:rebuild", 30) + try { + lock.lock() + status?.let { + checkStoreVersionOptRight(userId, storeId, status) + } + val storeCode = record.storeCode + val version = record.version + // 处理环境信息逻辑 + storeReleaseSpecBusService.doStoreEnvBus( + storeCode = storeCode, storeType = storeType, version = version, userId = userId + ) + val storeRunPipelineParam = StoreRunPipelineParam( + userId = userId, storeId = storeId + ) + storePipelineService.runPipeline(storeRunPipelineParam) + } finally { + lock.unlock() } - val storeCode = record.storeCode - val version = record.version - // 处理环境信息逻辑 - storeReleaseSpecBusService.doStoreEnvBus( - storeCode = storeCode, storeType = storeType, version = version, userId = userId - ) - val storeRunPipelineParam = StoreRunPipelineParam( - userId = userId, storeId = storeId - ) - storePipelineService.runPipeline(storeRunPipelineParam) return true }