From 2bb415e06ec1a5475df2aacc43aee975ddd02bd5 Mon Sep 17 00:00:00 2001 From: zacYL <100330102+zacYL@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:25:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=85=E7=90=86=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=83=A8=E5=88=86=E9=A1=B9=E7=9B=AE=20#1871?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/bkrepo/job/batch/ArtifactCleanupJob.kt | 11 ++++++++++- .../bkrepo/job/batch/base/ActiveProjectService.kt | 4 +--- .../config/properties/ArtifactCleanupJobProperties.kt | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ArtifactCleanupJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ArtifactCleanupJob.kt index 968b460a8d..5360ccf89b 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ArtifactCleanupJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/ArtifactCleanupJob.kt @@ -36,6 +36,7 @@ import com.tencent.bkrepo.common.artifact.pojo.configuration.RepositoryConfigura import com.tencent.bkrepo.common.security.constant.MS_AUTH_HEADER_SECURITY_TOKEN import com.tencent.bkrepo.common.security.service.ServiceAuthManager import com.tencent.bkrepo.common.service.log.LoggerHolder +import com.tencent.bkrepo.job.IGNORE_PROJECT_PREFIX_LIST import com.tencent.bkrepo.job.PROJECT import com.tencent.bkrepo.job.REPO import com.tencent.bkrepo.job.batch.base.DefaultContextMongoDbJob @@ -92,11 +93,12 @@ class ArtifactCleanupJob( return Query() } - override fun getLockAtMostFor(): Duration = Duration.ofDays(14) + override fun getLockAtMostFor(): Duration = Duration.ofDays(1) override fun run(row: RepoData, collectionName: String, context: JobContext) { try { + if (ignoreProjectOrRepoCheck(row.projectId)) return val config = row.configuration.readJsonString() val cleanupStrategyMap = config.getSetting>(CLEAN_UP_STRATEGY) ?: return val cleanupStrategy = toCleanupStrategy(cleanupStrategyMap) ?: return @@ -129,6 +131,13 @@ class ArtifactCleanupJob( } } + /** + * 判断项目或者仓库是否不需要进行目录统计 + */ + private fun ignoreProjectOrRepoCheck(projectId: String): Boolean { + return IGNORE_PROJECT_PREFIX_LIST.firstOrNull { projectId.startsWith(it) } != null + } + private fun toCleanupStrategy(map: Map): CleanupStrategy? { val cleanupStrategy = CleanupStrategy( enable = map[CleanupStrategy::enable.name] as? Boolean ?: false, diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/base/ActiveProjectService.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/base/ActiveProjectService.kt index 9a1598a021..e3eb125211 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/base/ActiveProjectService.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/base/ActiveProjectService.kt @@ -101,9 +101,6 @@ class ActiveProjectService( return ArrayList(criteriaList).apply { add(TOperateLog::type.inValues(types)) } } - // all - activeProjects = findDistinct(TOperateLog::projectId.name, Criteria().andOperator(criteriaList)) - // download event downloadActiveProjects = findDistinct( TOperateLog::projectId.name, @@ -115,6 +112,7 @@ class ActiveProjectService( TOperateLog::projectId.name, Criteria().andOperator(buildTypesCriteriaList(UPLOAD_EVENTS)) ) + activeProjects = downloadActiveProjects.union(uploadActiveProjects).toMutableSet() // active users activeUsers = findDistinct(TOperateLog::userId.name, TOperateLog::userId.ne("")) diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/config/properties/ArtifactCleanupJobProperties.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/config/properties/ArtifactCleanupJobProperties.kt index 6009e4c387..42470969ba 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/config/properties/ArtifactCleanupJobProperties.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/config/properties/ArtifactCleanupJobProperties.kt @@ -36,5 +36,5 @@ data class ArtifactCleanupJobProperties( var projectList: List = listOf(), // 如配置仓库,则只清理该仓库下的仓库 var repoList: List = listOf(), - override var cron: String = "0 0 5 * * ?" + override var cron: String = "0 0 0 * * ?" ): MongodbJobProperties() \ No newline at end of file