[erlang-questions] how to debug a code with spawned processes

Dmitry mbike2000ru@REDACTED
Wed Feb 1 14:00:13 CET 2017


The code which spawns new processes works in normal situation (when it is triggered from another application), but it seams that when it is called from send_all it does not work as expected:+++++++++++++++++++++++++++++++++++++++++++++++++++++++
handle_cast({send_all}, State=#state{pgconn=Conn}) ->  SQLQuery = "select mobile_phone from push_tokens as pt inner join employees as e on e.id = pt.employee_id where e.active = true and pt.app_voip_token is not null",  {ok, _, Res} = epgsql:squery(Conn, SQLQuery),   io:format("Send_all was queried~n"),  [connect_down(binary_to_list(Phone)) || {Phone} <- Res],  {noreply, State};++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The problem that annoy is called only once (but it had to call send_it - 124 times)
The question - how to debug such application: how to trace whats going on in the "annoy" function. I use spawn_monitor to detect link failure.++++++++++++++++++++++++++++++++++++++++++++++++++++++++annoy (BinToken) ->  [send_it(A, BinToken) || A <- lists:seq(1,124)].++++++++++++++++++++++++++++++++++++++++++++++++++++++++
handle_cast({connect_down, Phone}, State=#state{pgconn=Conn}) ->
 TokenbyphoneQuery = "select app_voip_token from push_tokens where employee_id in (select id from employees where mobile_phone = '"++ Phone ++"')",  {ok, _, Res} = epgsql:squery(Conn, TokenbyphoneQuery),
%%  ets:insert(conn_up, {Phone, false}),
  case Res of    []  ->lager:info("This is Android phone : ~p ~n", [Phone]),ok;    [{BinToken}] ->
        case BinToken of            null ->        lager:info("This is Android phone : ~p ~n", [Phone]),ok;        _ ->      io:format("Bintoken is: ~p ~n", [BinToken]),%      Pid = spawn(pusher, annoy, [BinToken]),Pid = spawn_monitor(pusher, annoy, [BinToken]),    lager:info("Spawning annoyer PID: ~p for ~p~n", [Pid, Phone]),      global:register_name("push_" ++ Phone, Pid)        end

  {noreply, State};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170201/7ee44c55/attachment.htm>

More information about the erlang-questions mailing list