Skip to content

Commit 334df6a

Browse files
committed
Make admin git gc/fsck tasks run in background
1 parent 80db442 commit 334df6a

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

modules/repository/check.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func GitFsck(ctx context.Context) error {
3434
}
3535
repo := bean.(*models.Repository)
3636
repoPath := repo.RepoPath()
37-
log.Trace("Running health check on repository %s", repoPath)
37+
log.Trace("Running health check on repository %v", repo)
3838
if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
39+
log.Warn("Failed to health check repository (%v): %v", repo, err)
3940
desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
40-
log.Warn(desc)
4141
if err = models.CreateRepositoryNotice(desc); err != nil {
4242
log.Error("CreateRepositoryNotice: %v", err)
4343
}
@@ -72,13 +72,18 @@ func GitGcRepos(ctx context.Context) error {
7272
if err := repo.GetOwner(); err != nil {
7373
return err
7474
}
75+
log.Trace("Running git gc on %v", repo)
7576
if stdout, err := git.NewCommand(args...).
7677
SetDescription(fmt.Sprintf("Repository Garbage Collection: %s", repo.FullName())).
7778
RunInDirTimeout(
7879
time.Duration(setting.Git.Timeout.GC)*time.Second,
7980
repo.RepoPath()); err != nil {
8081
log.Error("Repository garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
81-
return fmt.Errorf("Repository garbage collection failed: Error: %v", err)
82+
desc := fmt.Sprintf("Repository garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
83+
if err = models.CreateRepositoryNotice(desc); err != nil {
84+
log.Error("CreateRepositoryNotice: %v", err)
85+
}
86+
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
8287
}
8388
return nil
8489
},

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ dashboard.delete_missing_repos_success = All repositories missing their Git file
17591759
dashboard.delete_generated_repository_avatars = Delete generated repository avatars
17601760
dashboard.delete_generated_repository_avatars_success = Generated repository avatars were deleted.
17611761
dashboard.git_gc_repos = Garbage collect all repositories
1762-
dashboard.git_gc_repos_success = All repositories have finished garbage collection.
1762+
dashboard.git_gc_repos_success = Garbage collection started for all repositories.
17631763
dashboard.resync_all_sshkeys = Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)
17641764
dashboard.resync_all_sshkeys_success = The public SSH keys controlled by Gitea have been updated.
17651765
dashboard.resync_all_hooks = Resynchronize pre-receive, update and post-receive hooks of all repositories.

routers/admin/admin.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package admin
77

88
import (
9+
gocontext "context"
910
"encoding/json"
1011
"fmt"
1112
"net/url"
@@ -178,8 +179,13 @@ func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
178179
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
179180
err = repo_module.DeleteMissingRepositories(ctx.User)
180181
case gitGCRepos:
181-
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
182-
err = repo_module.GitGcRepos(shutdownCtx)
182+
success = ctx.Tr("admin.dashboard.git_gc_repos_started")
183+
go graceful.GetManager().RunWithShutdownContext(func(ctx gocontext.Context) {
184+
err := repo_module.GitGcRepos
185+
if err != nil {
186+
log.Error("Error whilst running git gc: %v", err)
187+
}
188+
})
183189
case syncSSHAuthorizedKey:
184190
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
185191
err = models.RewriteAllPublicKeys()
@@ -194,7 +200,12 @@ func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
194200
go graceful.GetManager().RunWithShutdownContext(models.SyncExternalUsers)
195201
case gitFsck:
196202
success = ctx.Tr("admin.dashboard.git_fsck_started")
197-
err = repo_module.GitFsck(shutdownCtx)
203+
go graceful.GetManager().RunWithShutdownContext(func(ctx gocontext.Context) {
204+
err := repo_module.GitFsck
205+
if err != nil {
206+
log.Error("Error whilst running git fsck: %v", err)
207+
}
208+
})
198209
case deleteGeneratedRepositoryAvatars:
199210
success = ctx.Tr("admin.dashboard.delete_generated_repository_avatars_success")
200211
err = models.RemoveRandomAvatars()

0 commit comments

Comments
 (0)