Make max DB connection attempts a constant
This commit is contained in:
parent
66b116ecb2
commit
0df9e7075c
@ -61,6 +61,8 @@ import (
|
|||||||
_ "github.com/coreos/clair/ext/vulnsrc/ubuntu"
|
_ "github.com/coreos/clair/ext/vulnsrc/ubuntu"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxDBConnectionAttempts = 20
|
||||||
|
|
||||||
func waitForSignals(signals ...os.Signal) {
|
func waitForSignals(signals ...os.Signal) {
|
||||||
interrupts := make(chan os.Signal, 1)
|
interrupts := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupts, signals...)
|
signal.Notify(interrupts, signals...)
|
||||||
@ -134,8 +136,7 @@ func Boot(config *Config) {
|
|||||||
// Open database
|
// Open database
|
||||||
var db database.Datastore
|
var db database.Datastore
|
||||||
var dbError error
|
var dbError error
|
||||||
maxConnectionAttempts := 20
|
for attempts := 1; attempts <= maxDBConnectionAttempts; attempts++ {
|
||||||
for attempts := 1; attempts <= maxConnectionAttempts; attempts++ {
|
|
||||||
db, dbError = database.Open(config.Database)
|
db, dbError = database.Open(config.Database)
|
||||||
if dbError == nil {
|
if dbError == nil {
|
||||||
break
|
break
|
||||||
@ -143,7 +144,6 @@ func Boot(config *Config) {
|
|||||||
log.Error(dbError);
|
log.Error(dbError);
|
||||||
time.Sleep(time.Duration(attempts) * time.Second)
|
time.Sleep(time.Duration(attempts) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dbError != nil {
|
if dbError != nil {
|
||||||
log.Fatal(dbError)
|
log.Fatal(dbError)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user