What's a proper way of waiting for DB initializati...
# exposed
s
What's a proper way of waiting for DB initialization? I'm launching my app and DB simultaneously so my app fails with Connection Refused error. I've come up with the following solution but it looks messy:
Copy code
class Db(
    dbPort: Int,
    dbUser: String,
    dbPassword: String,
    dbHost: String,
    dbDb: String
) : Storage() {

    init {
        Database.connect(
            url = "jdbc:postgresql://$dbHost:$dbPort/$dbDb",
            user = dbUser,
            password = dbPassword
        )

        while (true) {
            try {
                transaction {
                    SchemaUtils.createMissingTablesAndColumns(ProductTable)
                }

                break
            } catch (e: Throwable) {
                println("Waiting for db...")

                Thread.sleep(1000)
            }
        }
    }
}