C epgsql, when the primary signal is disconnected, the socket connection is interrupted. Since the connection process is associated with the workflow, the workflow terminates and is restarted by the supervisor.
So, all you have to do is (c my_worker:init) handle the errors from pgsql:connectand connect to the backup server instead:
case pgsql:connect(Primary, Username, Password, Opts) of
{ok, C} -> {ok,
_Other -> pgsql:connect(Standby, Username, Password, Opts)
end.
In my (admittedly very superficial) testing, this works fine.
source
share