Skip to content
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

Move InitDBEngine from routers to better place #16116

Closed
6543 opened this issue Jun 8, 2021 · 1 comment
Closed

Move InitDBEngine from routers to better place #16116

6543 opened this issue Jun 8, 2021 · 1 comment
Labels
type/refactoring Existing code has been cleaned up. There should be no new functionality.

Comments

@6543
Copy link
Member

6543 commented Jun 8, 2021

func InitDBEngine(ctx context.Context) (err error) {
log.Info("Beginning ORM engine initialization.")
for i := 0; i < setting.Database.DBConnectRetries; i++ {
select {
case <-ctx.Done():
return fmt.Errorf("Aborted due to shutdown:\nin retry ORM engine initialization")
default:
}
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries)
if err = models.NewEngine(ctx, migrations.Migrate); err == nil {
break
} else if i == setting.Database.DBConnectRetries-1 {
return err
}
log.Error("ORM engine initialization attempt #%d/%d failed. Error: %v", i+1, setting.Database.DBConnectRetries, err)
log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second))
time.Sleep(setting.Database.DBConnectBackoff)
}
models.HasEngine = true
return nil
}

"...I think this might be better in modules/database.

If you think about what else is in here they're all handlers/middleware of some sort - this is very definitely not and therefore should not be here. ..."

Originally posted by @zeripath in #15800 (comment)

@6543 6543 changed the title I think this might be better in modules/database. Move InitDBEngine from routers to better place Jun 8, 2021
@6543 6543 added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Jun 8, 2021
@wxiaoguang
Copy link
Contributor

It should have been done.

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

No branches or pull requests

2 participants