Merge pull request #487 from ajgreenb/db-connection-backoff
Use a backoff approach when connecting to database
This commit is contained in:
commit
838dcb0872
@ -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...)
|
||||||
@ -132,10 +134,20 @@ func Boot(config *Config) {
|
|||||||
st := stopper.NewStopper()
|
st := stopper.NewStopper()
|
||||||
|
|
||||||
// Open database
|
// Open database
|
||||||
db, err := database.Open(config.Database)
|
var db database.Datastore
|
||||||
if err != nil {
|
var dbError error
|
||||||
log.Fatal(err)
|
for attempts := 1; attempts <= maxDBConnectionAttempts; attempts++ {
|
||||||
|
db, dbError = database.Open(config.Database)
|
||||||
|
if dbError == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.WithError(dbError).Error("failed to connect to database")
|
||||||
|
time.Sleep(time.Duration(attempts) * time.Second)
|
||||||
}
|
}
|
||||||
|
if dbError != nil {
|
||||||
|
log.Fatal(dbError)
|
||||||
|
}
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
// Start notifier
|
// Start notifier
|
||||||
|
Loading…
Reference in New Issue
Block a user