Backends failover tracking
Pretty useful piece of code:
is_pid_alive(Pid) when is_pid(Pid) -> rpc:call(node(Pid), erlang, is_process_alive, [Pid]).
Checking if some process is alive. But working only with Erlang processes. I cannot check the status of some general TCP server. Still pretty cool. Based on that function I added a status check to Reverl. Maybe will use it for the other proxy nodes checks. The result: gateway behaviour with RR backend choice and backends failover tracking. Usage:
$ erl 1> l(gproxy3). {module,gproxy3} 2> S1=gproxy3:start_be(fun(X) -> 2*X end). <0.33.0> 3> S2=gproxy3:start_be(fun(X) -> 3*X end). <0.35.0> 4> S3=gproxy3:start_be(fun(X) -> 4*X end). <0.37.0> 5> G=gproxy3:start_gw([S1,S2,S3]). <0.39.0> 6> gproxy3:rpc(G,21). 42 7> gproxy3:rpc(G,21). 63 8> gproxy3:rpc(G,21). 84 9> S4=gproxy3:start_be(fun(X) -> 5*X end). <0.44.0> 10> gproxy3:add_be(G,S4). {be_add,<0.44.0>} 11> gproxy3:del_be(G,S2). {be_del,<0.35.0>} 12> gproxy3:list_be(G). [<0.44.0>,<0.33.0>,<0.37.0>] 13> gproxy3:stop(S1). stop 14> gproxy3:rpc(G,21). 105 15> gproxy3:rpc(G,21). =ERROR REPORT==== 26-Feb-2007::17:55:38 === (<0.39.0> gproxy3:30) backend <0.33.0> is down 84 16> gproxy3:rpc(G,21). 105
Next step: to figure what parts can be handled by the already existing gen_server behaviour and rewrite my code to separate the differences.