how to debug a code with spawned processes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to debug a code with spawned processes

Dmitry
Hello,



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


    end,

  {noreply, State};


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: how to debug a code with spawned processes

Alex S.

1 февр. 2017 г., в 16:00, Dmitry <[hidden email]> написал(а):

Hello,



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)].
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A good start would be to use proc_lib for your troubles, it’ll allow you to see traces of processes exiting improperly. Do you actually receive messages from the monitor anywhere?


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions