Use a linear backoff when connecting to DB

Closes #159
This commit is contained in:
Aaron Greenberg 2017-11-10 16:38:02 -05:00
parent 39f00cd756
commit 66b116ecb2

View File

@ -132,10 +132,22 @@ 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) maxConnectionAttempts := 20
for attempts := 1; attempts <= maxConnectionAttempts; attempts++ {
db, dbError = database.Open(config.Database)
if dbError == nil {
break
} }
log.Error(dbError);
time.Sleep(time.Duration(attempts) * time.Second)
}
if dbError != nil {
log.Fatal(dbError)
}
defer db.Close() defer db.Close()
// Start notifier // Start notifier