Add DB connection retries
This commit is contained in:
parent
9f40327562
commit
a5e3ff8023
76
contrib/analyze-local-images/vendor/github.com/coreos/clair/database/pgsql/pgsql.go
generated
vendored
76
contrib/analyze-local-images/vendor/github.com/coreos/clair/database/pgsql/pgsql.go
generated
vendored
@ -98,6 +98,18 @@ func (pgSQL *pgSQL) Ping() bool {
|
||||
func Open(config *config.DatabaseConfig) (database.Datastore, error) {
|
||||
// Run migrations.
|
||||
if err := migrate(config.Source); 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 {
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
}
|
||||
@ -105,8 +117,21 @@ func Open(config *config.DatabaseConfig) (database.Datastore, error) {
|
||||
// Open database.
|
||||
db, err := sql.Open("postgres", config.Source)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
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 {
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
}
|
||||
|
||||
// Initialize cache.
|
||||
@ -220,13 +245,37 @@ func OpenForTest(name string, withTestData bool) (*pgSQLTest, error) {
|
||||
|
||||
// Create database.
|
||||
if err := createDatabase(dataSourceDefaultDatabase, dbName); 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 {
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
}
|
||||
}
|
||||
|
||||
// Open database.
|
||||
db, err := Open(&config.DatabaseConfig{Source: dataSourceTestDatabase, CacheSize: 0})
|
||||
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 {
|
||||
dropDatabase(dataSourceDefaultDatabase, dbName)
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
@ -237,11 +286,20 @@ func OpenForTest(name string, withTestData bool) (*pgSQLTest, error) {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
d, _ := ioutil.ReadFile(path.Join(path.Dir(filename)) + "/testdata/data.sql")
|
||||
_, err = db.(*pgSQL).Exec(string(d))
|
||||
if err != nil {
|
||||
dropDatabase(dataSourceDefaultDatabase, dbName)
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
}
|
||||
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 {
|
||||
log.Error(err)
|
||||
return nil, database.ErrCantOpen
|
||||
}
|
||||
|
||||
return &pgSQLTest{
|
||||
|
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/api/context.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/api/context.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/api/v1.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/api/v1.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/config.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/config.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/database.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/database.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils/errors.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils/errors.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils/types.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/utils/types.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/beorn7/perks/quantile.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/beorn7/perks/quantile.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/coreos/go-systemd/journal.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/coreos/go-systemd/journal.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/coreos/pkg/capnslog.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/coreos/pkg/capnslog.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/fernet/fernet-go.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/fernet/fernet-go.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/golang/protobuf/proto.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/golang/protobuf/proto.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/julienschmidt/httprouter.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/julienschmidt/httprouter.a
generated
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/client_golang/prometheus.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/client_golang/prometheus.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/client_model/go.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/client_model/go.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/common/expfmt.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/common/expfmt.a
generated
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/common/model.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/common/model.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/procfs.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/github.com/prometheus/procfs.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/gopkg.in/yaml.v2.a
generated
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/vendor/gopkg.in/yaml.v2.a
generated
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/worker.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/worker.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/worker/detectors.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/clair/worker/detectors.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/go-systemd/journal.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/go-systemd/journal.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/pkg/capnslog.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/coreos/pkg/capnslog.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/fatih/color.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/fatih/color.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/kr/text.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/kr/text.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/mattn/go-colorable.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/mattn/go-colorable.a
vendored
Normal file
Binary file not shown.
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/mattn/go-isatty.a
vendored
Normal file
BIN
contrib/analyze-local-images/vendor/pkg/darwin_amd64/github.com/mattn/go-isatty.a
vendored
Normal file
Binary file not shown.
1
contrib/analyze-local-images/vendor/src/github.com/coreos/clair
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/coreos/clair
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 97347ec44d927c854b93d6722964aa459e42a106
|
1
contrib/analyze-local-images/vendor/src/github.com/coreos/go-systemd
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/coreos/go-systemd
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a63dfec412dc3675ec36888f359f8a1e5c3f740d
|
1
contrib/analyze-local-images/vendor/src/github.com/coreos/pkg
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/coreos/pkg
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 3ac0863d7acf3bc44daf49afef8919af12f704ef
|
1
contrib/analyze-local-images/vendor/src/github.com/fatih/color
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/fatih/color
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 87d4004f2ab62d0d255e0a38f1680aa534549fe3
|
1
contrib/analyze-local-images/vendor/src/github.com/kr/text
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/kr/text
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7cafcd837844e784b526369c9bce262804aebc60
|
1
contrib/analyze-local-images/vendor/src/github.com/mattn/go-colorable
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/mattn/go-colorable
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit ed8eb9e318d7a84ce5915b495b7d35e0cfe7b5a8
|
1
contrib/analyze-local-images/vendor/src/github.com/mattn/go-isatty
vendored
Submodule
1
contrib/analyze-local-images/vendor/src/github.com/mattn/go-isatty
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
Loading…
Reference in New Issue
Block a user