Response for context on retry database connection (#9444)
This commit is contained in:
parent
e2fc0a0dfd
commit
050a8af424
|
@ -6,6 +6,7 @@ package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -57,6 +58,11 @@ func NewServices() {
|
||||||
func initDBEngine(ctx context.Context) (err error) {
|
func initDBEngine(ctx context.Context) (err error) {
|
||||||
log.Info("Beginning ORM engine initialization.")
|
log.Info("Beginning ORM engine initialization.")
|
||||||
for i := 0; i < setting.Database.DBConnectRetries; i++ {
|
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)
|
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries)
|
||||||
if err = models.NewEngine(ctx, migrations.Migrate); err == nil {
|
if err = models.NewEngine(ctx, migrations.Migrate); err == nil {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue