0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-12-10 17:35:25 +01:00

clean up the lock files created 24 hours ago

This commit is contained in:
Lunny Xiao 2025-09-01 23:09:52 -07:00
parent a6ac8f0611
commit 88be11d968
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 48 additions and 1 deletions

View File

@ -17,7 +17,7 @@ var lockFiles = []string{
// CleanupRepo cleans up the repository by removing unnecessary lock files.
func CleanupRepo(ctx context.Context, repo Repository) error {
return CleanFixedFileLocks(ctx, repo, time.Now())
return CleanFixedFileLocks(ctx, repo, time.Now().Add(-24*time.Hour))
}
// CleanFixedFileLocks removes lock files that haven't been modified since the last update.

View File

@ -224,6 +224,16 @@ func registerRebuildIssueIndexer() {
})
}
func registerCleanupRepoLockFiles() {
RegisterTaskFatal("cleanup_repo_lock_files", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 24h",
}, func(ctx context.Context, _ *user_model.User, config Config) error {
return repo_service.CleanupRepo(ctx)
})
}
func initExtendedTasks() {
registerDeleteInactiveUsers()
registerDeleteRepositoryArchives()
@ -239,4 +249,5 @@ func initExtendedTasks() {
registerDeleteOldSystemNotices()
registerGCLFS()
registerRebuildIssueIndexer()
registerCleanupRepoLockFiles()
}

View File

@ -0,0 +1,36 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repository
import (
"context"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
)
func CleanupRepo(ctx context.Context) error {
log.Trace("Doing: CleanupRepo")
if err := db.Iterate(
ctx,
nil,
func(ctx context.Context, repo *repo_model.Repository) error {
select {
case <-ctx.Done():
return db.ErrCancelledf("before cleanup repo lock files for %s", repo.FullName())
default:
}
return gitrepo.CleanupRepo(ctx, repo)
},
); err != nil {
log.Trace("Error: CleanupRepo: %v", err)
return err
}
log.Trace("Finished: CleanupRepo")
return nil
}