<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12px"><div id="yui_3_16_0_ym19_1_1485951721255_41869">Hello,</div><div id="yui_3_16_0_ym19_1_1485951721255_41869"><br></div><div id="yui_3_16_0_ym19_1_1485951721255_41869"><br></div><div id="yui_3_16_0_ym19_1_1485951721255_41869"><br></div><div id="yui_3_16_0_ym19_1_1485951721255_41869">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:</div><div id="yui_3_16_0_ym19_1_1485951721255_41869">+++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div id="yui_3_16_0_ym19_1_1485951721255_41869"><br></div><div id="yui_3_16_0_ym19_1_1485951721255_43689">handle_cast({send_all}, State=#state{pgconn=Conn}) -></div><div id="yui_3_16_0_ym19_1_1485951721255_43690"> 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",</div><div id="yui_3_16_0_ym19_1_1485951721255_43691"> {ok, _, Res} = epgsql:squery(Conn, SQLQuery),</div><div id="yui_3_16_0_ym19_1_1485951721255_43692"> io:format("Send_all was queried~n"),</div><div id="yui_3_16_0_ym19_1_1485951721255_43693"> <b id="yui_3_16_0_ym19_1_1485951721255_43753">[connect_down(binary_to_list(Phone)) || {Phone} <- Res],</b></div><div id="yui_3_16_0_ym19_1_1485951721255_43694"> {noreply, State};</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695">++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695">The problem that annoy is called only once (but it had to call send_it - 124 times)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695">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.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695">++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695"><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43840"><b>annoy (BinToken) -></b></div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43841"><b> [send_it(A, BinToken) || A <- lists:seq(1,124)].</b></div></div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43695">++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div id="yui_3_16_0_ym19_1_1485951721255_41869"><br></div><div id="yui_3_16_0_ym19_1_1485951721255_43578">handle_cast({connect_down, Phone}, State=#state{pgconn=Conn}) -></div><div id="yui_3_16_0_ym19_1_1485951721255_43579"><br id="yui_3_16_0_ym19_1_1485951721255_43580"></div><div id="yui_3_16_0_ym19_1_1485951721255_43581"> TokenbyphoneQuery = "select app_voip_token from push_tokens where employee_id in (select id from employees where mobile_phone = '"++ Phone ++"')",</div><div id="yui_3_16_0_ym19_1_1485951721255_43582"> {ok, _, Res} = epgsql:squery(Conn, TokenbyphoneQuery),</div><div id="yui_3_16_0_ym19_1_1485951721255_43583"><br id="yui_3_16_0_ym19_1_1485951721255_43584"></div><div id="yui_3_16_0_ym19_1_1485951721255_43585">%% ets:insert(conn_up, {Phone, false}),</div><div id="yui_3_16_0_ym19_1_1485951721255_43586"><br id="yui_3_16_0_ym19_1_1485951721255_43587"></div><div id="yui_3_16_0_ym19_1_1485951721255_43588"> case Res of</div><div id="yui_3_16_0_ym19_1_1485951721255_43589"> [] ->lager:info("This is Android phone : ~p ~n", [Phone]),ok;</div><div id="yui_3_16_0_ym19_1_1485951721255_43590"> [{BinToken}] -></div><div id="yui_3_16_0_ym19_1_1485951721255_43591"><br id="yui_3_16_0_ym19_1_1485951721255_43592"></div><div id="yui_3_16_0_ym19_1_1485951721255_43593"> case BinToken of</div><div id="yui_3_16_0_ym19_1_1485951721255_43594"> null -></div><div id="yui_3_16_0_ym19_1_1485951721255_43595"> lager:info("This is Android phone : ~p ~n", [Phone]),ok;</div><div id="yui_3_16_0_ym19_1_1485951721255_43596"> _ -></div><div id="yui_3_16_0_ym19_1_1485951721255_43597"> io:format("Bintoken is: ~p ~n", [BinToken]),</div><div id="yui_3_16_0_ym19_1_1485951721255_43598">% Pid = spawn(pusher, annoy, [BinToken]),</div><div id="yui_3_16_0_ym19_1_1485951721255_43599"><b id="yui_3_16_0_ym19_1_1485951721255_43793">Pid = spawn_monitor(pusher, annoy, [BinToken]),</b></div><div id="yui_3_16_0_ym19_1_1485951721255_43600"> lager:info("Spawning annoyer PID: ~p for ~p~n", [Pid, Phone]),</div><div id="yui_3_16_0_ym19_1_1485951721255_43601"> global:register_name("push_" ++ Phone, Pid)</div><div id="yui_3_16_0_ym19_1_1485951721255_43602"> end</div><div id="yui_3_16_0_ym19_1_1485951721255_43603"><br id="yui_3_16_0_ym19_1_1485951721255_43604"></div><div id="yui_3_16_0_ym19_1_1485951721255_43605"><br id="yui_3_16_0_ym19_1_1485951721255_43606"></div><div id="yui_3_16_0_ym19_1_1485951721255_43607"> end,</div><div id="yui_3_16_0_ym19_1_1485951721255_43608"><br id="yui_3_16_0_ym19_1_1485951721255_43609"></div><div id="yui_3_16_0_ym19_1_1485951721255_43610"> {noreply, State};</div><div dir="ltr" id="yui_3_16_0_ym19_1_1485951721255_43611"><br id="yui_3_16_0_ym19_1_1485951721255_43612"></div></div></body></html>