mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-11 21:44:59 +01:00
clean up the lock files created 24 hours ago
This commit is contained in:
parent
a6ac8f0611
commit
88be11d968
@ -17,7 +17,7 @@ var lockFiles = []string{
|
|||||||
|
|
||||||
// CleanupRepo cleans up the repository by removing unnecessary lock files.
|
// CleanupRepo cleans up the repository by removing unnecessary lock files.
|
||||||
func CleanupRepo(ctx context.Context, repo Repository) error {
|
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.
|
// CleanFixedFileLocks removes lock files that haven't been modified since the last update.
|
||||||
|
|||||||
@ -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() {
|
func initExtendedTasks() {
|
||||||
registerDeleteInactiveUsers()
|
registerDeleteInactiveUsers()
|
||||||
registerDeleteRepositoryArchives()
|
registerDeleteRepositoryArchives()
|
||||||
@ -239,4 +249,5 @@ func initExtendedTasks() {
|
|||||||
registerDeleteOldSystemNotices()
|
registerDeleteOldSystemNotices()
|
||||||
registerGCLFS()
|
registerGCLFS()
|
||||||
registerRebuildIssueIndexer()
|
registerRebuildIssueIndexer()
|
||||||
|
registerCleanupRepoLockFiles()
|
||||||
}
|
}
|
||||||
|
|||||||
36
services/repository/cleanup.go
Normal file
36
services/repository/cleanup.go
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user