I am writing an Elixir project that connects to a Postgres database through Ecto. The database server is located on a different server from the application itself and is more prone to outages that would not affect the Elixir project than the fact that they work on the same hardware.
When the application starts normally, a database connection is created automatically, and everything works fine. But if there is a connection error, Ecto simply logs any errors.
What I would like to do is determine the current connection status and report this information using a simple Plug to route to an external load balancer so that traffic can be redirected to a separate server with an active connection.
The problem is that I'm not sure how to determine if Ecto has a viable database connection, except for listening to a log that does not indicate that the database connection has been restored.
What can I call to determine if an Ecto connection is live and usable, preferably without making non-operational requests for this connection?
source
share