-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...-generic/src/main/kotlin/com/tencent/bkrepo/generic/listener/BuildDeletedEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |