Graceful: Xorm, RepoIndexer, Cron and Others (#9282)
* Change graceful to use a singleton obtained through GetManager instead of a global. * Graceful: Make TestPullRequests shutdownable * Graceful: Make the cron tasks graceful * Graceful: AddTestPullRequest run in graceful ctx * Graceful: SyncMirrors shutdown * Graceful: SetDefaultContext for Xorm to be HammerContext * Avoid starting graceful for migrate commands and checkout * Graceful: DeliverHooks now can be shutdown * Fix multiple syncing errors in modules/sync/UniqueQueue & Make UniqueQueue closable * Begin the process of making the repo indexer shutdown gracefully
This commit is contained in:
parent
8bea92c3dc
commit
e3c3b33ea7
37 changed files with 628 additions and 287 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/cron"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -171,10 +172,10 @@ func Dashboard(ctx *context.Context) {
|
|||
err = models.ReinitMissingRepositories()
|
||||
case syncExternalUsers:
|
||||
success = ctx.Tr("admin.dashboard.sync_external_users_started")
|
||||
go models.SyncExternalUsers()
|
||||
go graceful.GetManager().RunWithShutdownContext(models.SyncExternalUsers)
|
||||
case gitFsck:
|
||||
success = ctx.Tr("admin.dashboard.git_fsck_started")
|
||||
go models.GitFsck()
|
||||
go graceful.GetManager().RunWithShutdownContext(models.GitFsck)
|
||||
case deleteGeneratedRepositoryAvatars:
|
||||
success = ctx.Tr("admin.dashboard.delete_generated_repository_avatars_success")
|
||||
err = models.RemoveRandomAvatars()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package routers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -53,11 +54,11 @@ func NewServices() {
|
|||
}
|
||||
|
||||
// In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology
|
||||
func initDBEngine() (err error) {
|
||||
func initDBEngine(ctx context.Context) (err error) {
|
||||
log.Info("Beginning ORM engine initialization.")
|
||||
for i := 0; i < setting.Database.DBConnectRetries; i++ {
|
||||
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries)
|
||||
if err = models.NewEngine(migrations.Migrate); err == nil {
|
||||
if err = models.NewEngine(ctx, migrations.Migrate); err == nil {
|
||||
break
|
||||
} else if i == setting.Database.DBConnectRetries-1 {
|
||||
return err
|
||||
|
@ -71,9 +72,9 @@ func initDBEngine() (err error) {
|
|||
}
|
||||
|
||||
// GlobalInit is for global configuration reload-able.
|
||||
func GlobalInit() {
|
||||
func GlobalInit(ctx context.Context) {
|
||||
setting.NewContext()
|
||||
if err := git.Init(); err != nil {
|
||||
if err := git.Init(ctx); err != nil {
|
||||
log.Fatal("Git module init failed: %v", err)
|
||||
}
|
||||
setting.CheckLFSVersion()
|
||||
|
@ -88,7 +89,7 @@ func GlobalInit() {
|
|||
highlight.NewContext()
|
||||
external.RegisterParsers()
|
||||
markup.Init()
|
||||
if err := initDBEngine(); err == nil {
|
||||
if err := initDBEngine(ctx); err == nil {
|
||||
log.Info("ORM engine initialization successful!")
|
||||
} else {
|
||||
log.Fatal("ORM engine initialization failed: %v", err)
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/generate"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/user"
|
||||
|
@ -351,7 +352,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
|
|||
return
|
||||
}
|
||||
|
||||
GlobalInit()
|
||||
GlobalInit(graceful.GetManager().HammerContext())
|
||||
|
||||
// Create admin account
|
||||
if len(form.AdminName) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue