From c4db370a4a6b527486044edcf4b9c181a28b6fe1 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Sat, 25 Nov 2023 23:04:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=88=A0=E9=99=A4=E4=BB=BB=E5=8A=A1=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=87=86?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20#1323=20(#1486)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/job/batch/ExpiredNodeMarkupJob.kt | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ExpiredNodeMarkupJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ExpiredNodeMarkupJob.kt index 5f68c7dc74..f78e5a3e43 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ExpiredNodeMarkupJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ExpiredNodeMarkupJob.kt @@ -27,16 +27,17 @@ package com.tencent.bkrepo.job.batch -import com.tencent.bkrepo.common.mongo.constant.ID import com.tencent.bkrepo.job.SHARDING_COUNT import com.tencent.bkrepo.job.batch.base.DefaultContextMongoDbJob import com.tencent.bkrepo.job.batch.base.JobContext import com.tencent.bkrepo.job.batch.utils.TimeUtils import com.tencent.bkrepo.job.config.properties.ExpiredNodeMarkupJobProperties +import com.tencent.bkrepo.repository.api.NodeClient +import com.tencent.bkrepo.repository.constant.SYSTEM_USER +import com.tencent.bkrepo.repository.pojo.node.service.NodeDeleteRequest +import org.slf4j.LoggerFactory import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query -import org.springframework.data.mongodb.core.query.Update import org.springframework.data.mongodb.core.query.and import org.springframework.data.mongodb.core.query.isEqualTo import org.springframework.data.mongodb.core.query.where @@ -51,10 +52,13 @@ import java.time.LocalDateTime @EnableConfigurationProperties(ExpiredNodeMarkupJobProperties::class) class ExpiredNodeMarkupJob( properties: ExpiredNodeMarkupJobProperties, + private val nodeClient: NodeClient ) : DefaultContextMongoDbJob(properties) { data class Node( - val id: String, + val projectId: String, + val repoName: String, + val fullPath: String, val expireDate: LocalDateTime, val deleted: LocalDateTime? ) @@ -78,7 +82,9 @@ class ExpiredNodeMarkupJob( override fun mapToEntity(row: Map): Node { return Node( - row[ID].toString(), + row[Node::projectId.name].toString(), + row[Node::repoName.name].toString(), + row[Node::fullPath.name].toString(), TimeUtils.parseMongoDateTimeStr(row[Node::expireDate.name].toString())!!, TimeUtils.parseMongoDateTimeStr(row[Node::deleted.name].toString()) ) @@ -89,15 +95,15 @@ class ExpiredNodeMarkupJob( } override fun run(row: Node, collectionName: String, context: JobContext) { - val query = Query.query(Criteria.where(ID).isEqualTo(row.id)) - mongoTemplate.updateFirst( - query, - Update().set(Node::deleted.name, LocalDateTime.now()), - collectionName - ) + try { + nodeClient.deleteNode(NodeDeleteRequest(row.projectId, row.repoName, row.fullPath, SYSTEM_USER)) + } catch (e: Exception) { + logger.warn("delete expired node[$row] failed: $e") + } } companion object { private const val COLLECTION_NAME_PREFIX = "node_" + private val logger = LoggerFactory.getLogger(ExpiredNodeMarkupJob::class.java) } }