Skip to content

Commit

Permalink
Check the DB during /status/alive calls
Browse files Browse the repository at this point in the history
  • Loading branch information
joshk committed Dec 17, 2024
1 parent d0cfc57 commit 4895f20
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/nerves_hub_web/plugs/im_alive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ defmodule NervesHubWeb.Plugs.ImAlive do
def init(config), do: config

def call(%{request_path: "/status/alive"} = conn, _) do
case Ecto.Adapters.SQL.query(NervesHub.Repo, "SELECT true", []) do
{:ok, _} -> send_result(conn, 200, "Hello, Friend!")
_result -> send_result(conn, 500, "Sorry, Friend :(")
end
end

def call(conn, _), do: conn

defp send_result(conn, code, message) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello Friend!")
|> send_resp(code, message)
|> halt
end

def call(conn, _), do: conn
end

0 comments on commit 4895f20

Please sign in to comment.