gen-server

how to make a genserver to run with a frequency value Elixir

妖精的绣舞 提交于 2020-12-14 06:58:02
问题 I have seen many GenServer implementations, I am trying to create one with such specifications, But I am not sure its GenServer's use case. I have a state such as %{url: "abc.com/jpeg", name: "Camera1", id: :camera_one, frequency: 10} I have such 100 states, with different values, my use case contains on 5 steps. Start Each state as a Gen{ ? }. Send an HTTP request to that URL. Get results. Send another HTTP request with the data came from the first request. Put the Process to sleep. if the

how to make a genserver to run with a frequency value Elixir

丶灬走出姿态 提交于 2020-12-14 06:56:57
问题 I have seen many GenServer implementations, I am trying to create one with such specifications, But I am not sure its GenServer's use case. I have a state such as %{url: "abc.com/jpeg", name: "Camera1", id: :camera_one, frequency: 10} I have such 100 states, with different values, my use case contains on 5 steps. Start Each state as a Gen{ ? }. Send an HTTP request to that URL. Get results. Send another HTTP request with the data came from the first request. Put the Process to sleep. if the

Why my supervisor terminating?

倾然丶 夕夏残阳落幕 提交于 2020-04-29 09:17:25
问题 I'm very new to OTP, I'm trying to create simple example to understand supervisor behaviour: Here is simple increment server -module( inc_serv ). -behaviour( gen_server ). -export( [ start/0, inc/1, stop/0 ] ). -export( [ init/1, handle_call/3, terminate/2 ] ). start() -> gen_server:start_link( { local, ?MODULE }, ?MODULE, no_args, [] ). stop() -> gen_server:call( ?MODULE, stop ). inc( Num ) -> gen_server:call( ?MODULE, { num, Num } ). init( no_args ) -> io:format( "~p~n", [ "Increment server

Why my supervisor terminating?

空扰寡人 提交于 2020-04-29 09:17:21
问题 I'm very new to OTP, I'm trying to create simple example to understand supervisor behaviour: Here is simple increment server -module( inc_serv ). -behaviour( gen_server ). -export( [ start/0, inc/1, stop/0 ] ). -export( [ init/1, handle_call/3, terminate/2 ] ). start() -> gen_server:start_link( { local, ?MODULE }, ?MODULE, no_args, [] ). stop() -> gen_server:call( ?MODULE, stop ). inc( Num ) -> gen_server:call( ?MODULE, { num, Num } ). init( no_args ) -> io:format( "~p~n", [ "Increment server

Erlang Supervisor Strategy For Restarting Connections to Downed Hosts

一笑奈何 提交于 2020-01-22 19:48:26
问题 I'm using erlang as a bridge between services and I was wondering what advice people had for handling downed connections? I'm taking input from local files and piping them out to AMQP and it's conceivable that the AMQP broker could go down. For that case I would want to keep retrying to connect to the AMQP server but I don't want to peg the CPU with those connections attempts. My inclination is to put a sleep into the reboot of the AMQP code. Wouldn't that 'hack' essentially circumvent the

Erlang gen_server with long-running tasks

筅森魡賤 提交于 2020-01-12 05:21:19
问题 Good day, I have a gen_server process which does some long-running state-updating tasks periodically in handle_info : handle_info(trigger, State) -> NewState = some_long_running_task(), erlang:send_after(?LOOP_TIME, self(), trigger), {noreply, NewState}. But when such task runs, then whole server gets unresponsive and any call to it leads to whole server crash: my_gen_server:status(). ** exception exit: {timeout,{gen_server,call,[my_gen_server,status]}} in function gen_server:call/2 How it is

Elixir GenServer parallel handle_call

≯℡__Kan透↙ 提交于 2020-01-04 06:51:14
问题 There is an application on the Phoenix Framework. There is a need for GenServer, which will check some values. Validation of these values is started from the controller (a request comes from the client, the GenServer value checks, the client receives a response). Once handle_call is synchronous, then what happens when 10 clients call 10 calls handle_call at a time? All 10 calls will be processed in parallel or in the order of the queue? 回答1: GenServer will process only single call other

Elixir GenServer parallel handle_call

≡放荡痞女 提交于 2020-01-04 06:50:10
问题 There is an application on the Phoenix Framework. There is a need for GenServer, which will check some values. Validation of these values is started from the controller (a request comes from the client, the GenServer value checks, the client receives a response). Once handle_call is synchronous, then what happens when 10 clients call 10 calls handle_call at a time? All 10 calls will be processed in parallel or in the order of the queue? 回答1: GenServer will process only single call other

Getting gen_server/gen_fsm state for debugging

痞子三分冷 提交于 2020-01-01 02:16:07
问题 Is it possible to obtain the current state of a gen_server process (presumably by sending some system message)? It could be useful when debugging. Of course, I can add a message which returns the current state to handle_call : get_state(Server) -> gen_server:call(Server, '$get_state'). %% in every gen_server I want to debug ... handle_call('$get_state', _From, State) -> {reply, State, State}; ... but is there something built-in (even if it is a bit hacky)? 回答1: Use sys:get_status/1,2 function

How does an Erlang gen_server start_link a gen_server on another node?

亡梦爱人 提交于 2019-12-23 02:04:41
问题 I have an Erlang application that is getting a little too resource-hungry to stay on one node. I'm in the process of making gen_servers move from one process to another - which turns out to be relatively easy. I'm at the last hurdle: getting the factory process that creates these gen_servers to spawn them on the remote node instead of the local one. The default behavior of start_link is clearly to start locally only, but I don't see any option to change that. It would seem that I'm going to