Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres health check in Elixir

I am trying to do a simple health check on my postgres database for elixir.

In rails I would do something like: ActiveRecord::Base.verify_active_connections

Is there anything similar on elixir?

like image 619
Gary Avatar asked Nov 05 '15 18:11

Gary


1 Answers

This is the best that I found.

status = try do
  Ecto.Adapters.SQL.query(ProjectName.Repo, "select 1", [])
  :ok
rescue
  DBConnection.ConnectionError -> :error
end

It just sends a select 1 request to the sql server and if we get an exit we return :error else we return :ok

like image 192
Gary Avatar answered Sep 20 '22 05:09

Gary