Questions tagged [gen-server]

gen_server stands for "generic server", a module behaviour in Erlang.

315 questions
0
votes
1 answer

Phoenix application on a fleet of machines

I'm developing a real-time Phoenix App using it's Channel and Socket modules. The App consists of a few processes and GenServers. I have a use case, where on an event (which is an API call from a microservice), I need to broadcast messages to all…
0
votes
1 answer

Understanding Genserver - start_link/0 conflicts with default

I'm trying implement a GenServer to monitor one of my functions and then restart the process after 1 hour. Forgive the lack of knowledge as this if my first experience with GenServer. CODE: defmodule Statcasters.Scheduler do use GenServer use…
Bitwise
  • 8,021
  • 22
  • 70
  • 161
0
votes
1 answer

Why doesn't my GenServer handle_cast get called

I am using GenServer in my module as below. In the init method, it creates a redis connection to the database. The put method will send values to be saved in redisdb. The handle_cast method will call the command on redis connection to do the…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
0
votes
1 answer

Ecto changesets and GenServers using TDD

I'm testing a GenServer by unit testing the handle_{call,cast,info} callbacks. One of my doctests is as follows: @doc """ Call the GenServer to retrieve…
category
  • 2,113
  • 2
  • 22
  • 46
0
votes
1 answer

GenStage: retry handle_demand when GenServer updates

If my GenStage's handle_demand/2 method looks like this: def handle_demand(demand, _state) when demand > 0 do case Queue.dequeue do nil -> Logger.debug("Queue empty.") {:noreply, [], []} {job, updated_queue} -> {:noreply, job,…
t56k
  • 6,769
  • 9
  • 52
  • 115
0
votes
1 answer

Elixir: Loop the actor to rerun itself

I am making an master-worker application. The Master code is as follows. This code asynchronously calls workers in start_link. Once the workers are done with their work, they report to master using handle_cast asynchronous call. After this I intend…
Prince Bhatti
  • 4,671
  • 4
  • 18
  • 24
0
votes
0 answers

Test an Elixir Monitor Process for Phoenix Channel Close without a timer delay?

I currently have functionality which tracks when a user connects to a channel and when a user leaves a channel. This is implemented from this stackoverflow answer here. I have written the following test (see commit) to verify my callback…
0
votes
1 answer

gen_server stop badmatch on sub process stopped

I have a table process which creates a pidfor a board as part of its state with go(). I am testing that terminating the table also terminates the board. But the board is not stopping as expected. My test: kills_board_test() -> {ok, Table} =…
quantumpotato
  • 9,637
  • 14
  • 70
  • 146
0
votes
1 answer

How to spawn a Erlang process dynamically for one activity and kill it once activity done

There are many parallel requests coming to one erlang OTP (gen_server) process. One process is not sufficient to handle this. I can have fix number pool of same processes to handle this using Poolboy or worker_pool. But I dont want to have fix set…
ManasP
  • 31
  • 6
0
votes
1 answer

bad argument in call to fxml_stream:new(undefined, 65536)

I am not familiar with erlang and new to ejabberd. I am getting following error in crash.log. 2017-06-22 04:58:53 =CRASH REPORT==== crasher: initial call: ejabberd_receiver:init/1 pid: <0.23584.370> registered_name: [] exception exit:…
Khadija
  • 63
  • 5
0
votes
1 answer

Task.await timeout which is causing GenServer to terminate

My Genserver terminates after a little while, after sending a few http requests. I can't understand the reason: [error] GenServer MyGenServer terminating ** (stop) exited in: Task.await(%Task{owner: #PID<0.420.0>, pid: #PID<0.1054.0>, ref:…
Jodimoro
  • 4,355
  • 3
  • 11
  • 18
0
votes
1 answer

Why do I get twice the same message?

I'm quite new in Erlang, and I'm developing a little program to simulate a robot which collect cans: -export([start/0]). start()-> Believes=#{bin_position=>0, num_cans=>1, can_position=>4, my_position=>1}, PID=spawn(fun()->…
0
votes
1 answer

GenServer and its state

I this this simple genserver: def handle_info(:tick, items) do items2 = do_job(items) tick() {:noreply, items2} end In "do_job" I need to a) iterate throug items, b) make an http request which can take long and c) depending on a response,…
user7905648
  • 117
  • 6
0
votes
1 answer

gen_server:call - how to send message

Now Im playing with the gen_server I have two modules - one is Gen Server mod, second - logic module and would like to send the message to the PID through the gen_server:call here is the snip of code: lookup_by_date(FromTime, ToTime) -> …
Eugen Dubrovin
  • 888
  • 5
  • 15
0
votes
3 answers

gen_server run slower when mailbox get bigger

I've got a problem, I use gen server to do some simple work like this: one handle_cast to do a long time work(takes 60 seconds) one handle_cast to do a very fast work everything is fine when traffic is low. But when the server process is…
蛋汤饭
  • 31
  • 3