mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user