Add more retry options

This commit is contained in:
Heather Huggins 2016-09-23 11:29:25 -07:00
parent a5e3ff8023
commit 55f1c9cac8

View File

@ -181,6 +181,20 @@ func migrate(dataSource string) error {
func createDatabase(dataSource, databaseName string) error { func createDatabase(dataSource, databaseName string) error {
// Open database. // Open database.
db, err := sql.Open("postgres", dataSource) db, err := sql.Open("postgres", dataSource)
if err != nil {
try.Do(func(attempt int) (retry bool, err error) {
retry = attempt < 5 // try 5 times
defer func() {
if r := recover(); r != nil {
err = errors.New(fmt.Sprintf("panic: %v", r))
}
}()
value, err = SomeFunction()
return
})
}
if err != nil { if err != nil {
return fmt.Errorf("could not open database (CreateDatabase): %v", err) return fmt.Errorf("could not open database (CreateDatabase): %v", err)
} }
@ -200,6 +214,18 @@ func createDatabase(dataSource, databaseName string) error {
func dropDatabase(dataSource, databaseName string) error { func dropDatabase(dataSource, databaseName string) error {
// Open database. // Open database.
db, err := sql.Open("postgres", dataSource) db, err := sql.Open("postgres", dataSource)
if err != nil {
try.Do(func(attempt int) (retry bool, err error) {
retry = attempt < 5 // try 5 times
defer func() {
if r := recover(); r != nil {
err = errors.New(fmt.Sprintf("panic: %v", r))
}
}()
value, err = SomeFunction()
return
})
}
if err != nil { if err != nil {
return fmt.Errorf("could not open database (DropDatabase): %v", err) return fmt.Errorf("could not open database (DropDatabase): %v", err)
} }