Skip to content

Make admin git gc tasks run in background #10629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/repository/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func GitFsck(ctx context.Context) error {
}
repo := bean.(*models.Repository)
repoPath := repo.RepoPath()
log.Trace("Running health check on repository %s", repoPath)
log.Trace("Running health check on repository %v", repo)
if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
log.Warn("Failed to health check repository (%v): %v", repo, err)
desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
log.Warn(desc)
if err = models.CreateRepositoryNotice(desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
Expand Down Expand Up @@ -72,13 +72,18 @@ func GitGcRepos(ctx context.Context) error {
if err := repo.GetOwner(); err != nil {
return err
}
log.Trace("Running git gc on %v", repo)
Copy link
Member

@silverwind silverwind Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What logging config do I need to see these? I have LEVEL = Trace and tried both file/stdout logging. Also, I'd suggest raising this and similar ones to Info.

if stdout, err := git.NewCommand(args...).
SetDescription(fmt.Sprintf("Repository Garbage Collection: %s", repo.FullName())).
RunInDirTimeout(
time.Duration(setting.Git.Timeout.GC)*time.Second,
repo.RepoPath()); err != nil {
log.Error("Repository garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
return fmt.Errorf("Repository garbage collection failed: Error: %v", err)
desc := fmt.Sprintf("Repository garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
if err = models.CreateRepositoryNotice(desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ dashboard.delete_missing_repos_success = All repositories missing their Git file
dashboard.delete_generated_repository_avatars = Delete generated repository avatars
dashboard.delete_generated_repository_avatars_success = Generated repository avatars were deleted.
dashboard.git_gc_repos = Garbage collect all repositories
dashboard.git_gc_repos_success = All repositories have finished garbage collection.
dashboard.git_gc_repos_success = Garbage collection started for all repositories.
dashboard.resync_all_sshkeys = Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)
dashboard.resync_all_sshkeys_success = The public SSH keys controlled by Gitea have been updated.
dashboard.resync_all_hooks = Resynchronize pre-receive, update and post-receive hooks of all repositories.
Expand Down
17 changes: 14 additions & 3 deletions routers/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package admin

import (
gocontext "context"
"encoding/json"
"fmt"
"net/url"
Expand Down Expand Up @@ -178,8 +179,13 @@ func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
err = repo_module.DeleteMissingRepositories(ctx.User)
case gitGCRepos:
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
err = repo_module.GitGcRepos(shutdownCtx)
success = ctx.Tr("admin.dashboard.git_gc_repos_started")
go graceful.GetManager().RunWithShutdownContext(func(ctx gocontext.Context) {
err := repo_module.GitGcRepos
if err != nil {
log.Error("Error whilst running git gc: %v", err)
}
})
case syncSSHAuthorizedKey:
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
err = models.RewriteAllPublicKeys()
Expand All @@ -194,7 +200,12 @@ func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
go graceful.GetManager().RunWithShutdownContext(models.SyncExternalUsers)
case gitFsck:
success = ctx.Tr("admin.dashboard.git_fsck_started")
err = repo_module.GitFsck(shutdownCtx)
go graceful.GetManager().RunWithShutdownContext(func(ctx gocontext.Context) {
err := repo_module.GitFsck
if err != nil {
log.Error("Error whilst running git fsck: %v", err)
}
})
case deleteGeneratedRepositoryAvatars:
success = ctx.Tr("admin.dashboard.delete_generated_repository_avatars_success")
err = models.RemoveRandomAvatars()
Expand Down