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()
// Open database
db, err := database.Open(config.Database)
if err != nil {
log.Fatal(err)
var db database.Datastore
var dbError error
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()
// Start notifier