hashicorp-demoapp / product-api-go

Products API written in Go
Mozilla Public License 2.0
42 stars 26 forks source link

Support DB connection max retries parameter #30

Closed cocolavayen closed 1 year ago

cocolavayen commented 1 year ago

This PR introduces the changes to handle the maximum number of database connection retries. This new parameters should be set in the configuration file read by the application (conf.json).

Also, on Windows OS, sometimes the connection attempt freezes and it does not respond again. product-api uses the sqlx package to create the DB connection. This occurs in the internal method “ping” of this package which by default waits indefinitely. To solve this issue, based/on sqlx documentation, we added the “connect_timeout” variable in the DB connection string (db_parameter) of the config.json file with 10 seconds as default value. This new variable allows to set the maximum time to wait for the connection. If product-api can’t connect to database, it continues to next retry.