fix db connection in docker compose

This commit is contained in:
Zhang Minghan 2023-12-25 14:07:10 +08:00
parent 823025eddd
commit 456b4e0c01

View File

@ -31,7 +31,11 @@ func ConnectMySQL() *sql.DB {
))
if err != nil || db.Ping() != nil {
log.Println(fmt.Sprintf("[connection] failed to connect to mysql server: %s, will retry in 5 seconds", viper.GetString("mysql.host")))
return nil
utils.Sleep(5)
db.Close()
return ConnectMySQL()
} else {
log.Println(fmt.Sprintf("[connection] connected to mysql server (host: %s)", viper.GetString("mysql.host")))
}