Do not crash due to failed backend components
This commit is contained in:
parent
aeb6db4f77
commit
4a2b6a4948
2 changed files with 27 additions and 14 deletions
|
@ -28,8 +28,8 @@ defmodule HAHandler.DRBD.Watcher do
|
||||||
hostname = Keyword.get(opts, :hostname)
|
hostname = Keyword.get(opts, :hostname)
|
||||||
password = Keyword.get(opts, :password)
|
password = Keyword.get(opts, :password)
|
||||||
|
|
||||||
{:ok, pid} = connect(hostname, password)
|
case connect(hostname, password) do
|
||||||
|
{:ok, pid} ->
|
||||||
state = %{
|
state = %{
|
||||||
backend: pid,
|
backend: pid,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
|
@ -37,6 +37,14 @@ defmodule HAHandler.DRBD.Watcher do
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
|
{:error, err} ->
|
||||||
|
|
||||||
|
# Wait for 10 seconds so that the supervisor does not loop on dead node
|
||||||
|
# (and reach the max_restart threshold / stop trying).
|
||||||
|
Process.sleep(10_000)
|
||||||
|
|
||||||
|
{:error, err}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -12,14 +12,19 @@ defmodule HAHandler.PGSQL.Watcher do
|
||||||
# successful.
|
# successful.
|
||||||
# TODO: set dbconnections backoff and connect hooks
|
# TODO: set dbconnections backoff and connect hooks
|
||||||
# See https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex#L343
|
# See https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex#L343
|
||||||
{:ok, pid} = Postgrex.start_link(opts)
|
case Postgrex.start_link(opts) do
|
||||||
|
{:ok, pid} ->
|
||||||
state = %{
|
state = %{
|
||||||
backend: pid,
|
backend: pid,
|
||||||
hostname: Keyword.get(opts, :hostname)
|
hostname: Keyword.get(opts, :hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
|
{:error, err} ->
|
||||||
|
# Will be catched by the supervisor if anything happen. It should not
|
||||||
|
# be triggered even if a PGSQL node down, since Postgrex has its own
|
||||||
|
# surpervision tree.
|
||||||
|
{:error, err}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
Loading…
Reference in a new issue