Skip to content

Commit

Permalink
feat: 清理任务过滤部分项目 TencentBlueKing#1871
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL authored Mar 13, 2024
1 parent fe01812 commit 2bb415e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<RepositoryConfiguration>()
val cleanupStrategyMap = config.getSetting<Map<String, Any>>(CLEAN_UP_STRATEGY) ?: return
val cleanupStrategy = toCleanupStrategy(cleanupStrategyMap) ?: return
Expand Down Expand Up @@ -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<String, Any>): CleanupStrategy? {
val cleanupStrategy = CleanupStrategy(
enable = map[CleanupStrategy::enable.name] as? Boolean ?: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ data class ArtifactCleanupJobProperties(
var projectList: List<String> = listOf(),
// 如配置仓库,则只清理该仓库下的仓库
var repoList: List<String> = listOf(),
override var cron: String = "0 0 5 * * ?"
override var cron: String = "0 0 0 * * ?"
): MongodbJobProperties()

0 comments on commit 2bb415e

Please sign in to comment.