Skip to content

Commit 88be11d

Browse files
committed
clean up the lock files created 24 hours ago
1 parent a6ac8f0 commit 88be11d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

modules/gitrepo/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var lockFiles = []string{
1717

1818
// CleanupRepo cleans up the repository by removing unnecessary lock files.
1919
func CleanupRepo(ctx context.Context, repo Repository) error {
20-
return CleanFixedFileLocks(ctx, repo, time.Now())
20+
return CleanFixedFileLocks(ctx, repo, time.Now().Add(-24*time.Hour))
2121
}
2222

2323
// CleanFixedFileLocks removes lock files that haven't been modified since the last update.

services/cron/tasks_extended.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ func registerRebuildIssueIndexer() {
224224
})
225225
}
226226

227+
func registerCleanupRepoLockFiles() {
228+
RegisterTaskFatal("cleanup_repo_lock_files", &BaseConfig{
229+
Enabled: false,
230+
RunAtStart: false,
231+
Schedule: "@every 24h",
232+
}, func(ctx context.Context, _ *user_model.User, config Config) error {
233+
return repo_service.CleanupRepo(ctx)
234+
})
235+
}
236+
227237
func initExtendedTasks() {
228238
registerDeleteInactiveUsers()
229239
registerDeleteRepositoryArchives()
@@ -239,4 +249,5 @@ func initExtendedTasks() {
239249
registerDeleteOldSystemNotices()
240250
registerGCLFS()
241251
registerRebuildIssueIndexer()
252+
registerCleanupRepoLockFiles()
242253
}

services/repository/cleanup.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repository
5+
6+
import (
7+
"context"
8+
9+
"code.gitea.io/gitea/models/db"
10+
repo_model "code.gitea.io/gitea/models/repo"
11+
"code.gitea.io/gitea/modules/gitrepo"
12+
"code.gitea.io/gitea/modules/log"
13+
)
14+
15+
func CleanupRepo(ctx context.Context) error {
16+
log.Trace("Doing: CleanupRepo")
17+
18+
if err := db.Iterate(
19+
ctx,
20+
nil,
21+
func(ctx context.Context, repo *repo_model.Repository) error {
22+
select {
23+
case <-ctx.Done():
24+
return db.ErrCancelledf("before cleanup repo lock files for %s", repo.FullName())
25+
default:
26+
}
27+
return gitrepo.CleanupRepo(ctx, repo)
28+
},
29+
); err != nil {
30+
log.Trace("Error: CleanupRepo: %v", err)
31+
return err
32+
}
33+
34+
log.Trace("Finished: CleanupRepo")
35+
return nil
36+
}

0 commit comments

Comments
 (0)