Skip to content

Commit

Permalink
feat: 插件发布操作做成幂等 TencentBlueKing#5201
Browse files Browse the repository at this point in the history
  • Loading branch information
ddlin0719 committed Sep 17, 2021
1 parent a154ec7 commit 53391fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class QualityControlPointDao {
val filterResult = mutableListOf<TQualityControlPointRecord>()
// 获取生产跑的,或者测试项目对应的
result.groupBy { it.elementType }.forEach { elementType, list ->
val testControlPoint = list.firstOrNull {
projectId.isBlank() && it.testProject == projectId
}
val testControlPoint = list.firstOrNull { it.testProject == projectId }
val prodControlPoint = list.firstOrNull { it.testProject.isNullOrBlank() }
if (testControlPoint != null) {
filterResult.add(testControlPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
package com.tencent.devops.store.service.atom.impl

import com.tencent.devops.common.client.Client
import com.tencent.devops.common.redis.RedisLock
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.quality.api.v2.ServiceQualityControlPointMarketResource
import com.tencent.devops.quality.api.v2.ServiceQualityIndicatorMarketResource
import com.tencent.devops.quality.api.v2.ServiceQualityMetadataMarketResource
Expand All @@ -44,23 +46,36 @@ import org.springframework.stereotype.Service
*/
@Service
class AtomQualityServiceImpl @Autowired constructor(
private val client: Client
private val client: Client,
private val redisOperation: RedisOperation
) : AtomQualityService {

private val logger = LoggerFactory.getLogger(AtomQualityServiceImpl::class.java)

override fun updateQualityInApprove(atomCode: String, atomStatus: Byte) {
logger.info("update quality atomStatus: $atomStatus")
if (atomStatus == AtomStatusEnum.RELEASED.status.toByte()) {
// 审核通过就刷新基础数据和指标
val metadataMap =
client.get(ServiceQualityMetadataMarketResource::class).refreshMetadata(atomCode).data ?: mapOf()
client.get(ServiceQualityIndicatorMarketResource::class).refreshIndicator(atomCode, metadataMap)
client.get(ServiceQualityControlPointMarketResource::class).refreshControlPoint(atomCode)
logger.info("update quality atomStatus: $atomCode, $atomStatus")

val key = this::class.java.name + "#" + Thread.currentThread().stackTrace[1].methodName + "#" + atomCode
val lock = RedisLock(redisOperation, key, 3600L)

try {
if (!lock.tryLock()) {
throw IllegalArgumentException("get lock failed and do not do update quality in approve")
}

if (atomStatus == AtomStatusEnum.RELEASED.status.toByte()) {
// 审核通过就刷新基础数据和指标
val metadataMap =
client.get(ServiceQualityMetadataMarketResource::class).refreshMetadata(atomCode).data ?: mapOf()
client.get(ServiceQualityIndicatorMarketResource::class).refreshIndicator(atomCode, metadataMap)
client.get(ServiceQualityControlPointMarketResource::class).refreshControlPoint(atomCode)
}
// 删除测试数据
client.get(ServiceQualityMetadataMarketResource::class).deleteTestMetadata(atomCode)
client.get(ServiceQualityIndicatorMarketResource::class).deleteTestIndicator(atomCode)
client.get(ServiceQualityControlPointMarketResource::class).deleteTestControlPoint(atomCode)
} finally {
lock.unlock()
}
// 删除测试数据
client.get(ServiceQualityMetadataMarketResource::class).deleteTestMetadata(atomCode)
client.get(ServiceQualityIndicatorMarketResource::class).deleteTestIndicator(atomCode)
client.get(ServiceQualityControlPointMarketResource::class).deleteTestControlPoint(atomCode)
}
}

0 comments on commit 53391fb

Please sign in to comment.