Skip to content

Commit

Permalink
fix: 新增Generic下Block事件监听 #2813
Browse files Browse the repository at this point in the history
  • Loading branch information
zzdjx committed Dec 11, 2024
1 parent c21d488 commit 318f65a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ open class NodeDeleteSupport(
routerControllerClient.removeNodes(projectId, repoName, fullPath)
}
publishEvent(buildDeletedEvent(projectId, repoName, fullPath, operator))
val blockCriteria = buildCriteria(projectId, repoName, fullPath, deleteTime)
val node = nodeDao.findOne(Query(blockCriteria))
if (node?.sha256 == FAKE_SHA256) {
nodeBaseService.blockNodeService.deleteBlocks(projectId, repoName, fullPath)
}
}
} catch (exception: DuplicateKeyException) {
logger.warn("Delete node[$resourceKey] by [$operator] error: [${exception.message}]")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.tencent.bkrepo.generic.listener

import com.tencent.bkrepo.common.artifact.api.ArtifactInfo
import com.tencent.bkrepo.common.artifact.event.base.ArtifactEvent
import com.tencent.bkrepo.common.artifact.event.base.EventType
import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.metadata.constant.FAKE_SHA256
import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService
import com.tencent.bkrepo.common.metadata.service.node.NodeService
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Conditional
import org.springframework.context.event.EventListener
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component

@Component
@Conditional(SyncCondition::class)
class BuildDeletedEventListener(
private val nodeService: NodeService,
private val blockNodeService: BlockNodeService
) {

@Async
@EventListener(ArtifactEvent::class)
fun handle(event: ArtifactEvent) {
if (event.type == EventType.NODE_DELETED) {
logger.info("accept artifact delete event: $event")
consumer(event)
}
}

private fun consumer(event: ArtifactEvent) {
with(event) {
val node = nodeService.getDeletedNodeDetail(ArtifactInfo(projectId, repoName, resourceKey)).firstOrNull()
if (node?.sha256 == FAKE_SHA256 && !node.folder) {
blockNodeService.deleteBlocks(projectId, repoName, resourceKey)
}
}
}

companion object {
private val logger = LoggerFactory.getLogger(BuildDeletedEventListener::class.java)
}
}

0 comments on commit 318f65a

Please sign in to comment.