otp

Issue when registering two local process with gproc within cowboy websocket handler

北战南征 提交于 2019-12-25 08:24:47
问题 I tried to register a bunch of processes with a unique family name with gproc under a cowboy websocket handler. In my handler I created two method, the first one is to handle registration: websocket_handle({text, <<"Reg: ",Message/binary>>}, State) -> io:format("Client ~p requesting to register ~n",[Message]), MyPID=list_to_binary(pid_to_list(self())), {[{_,Family}]}=jiffy:decode(Message), io:format("Client ~p requesting to register ~n",[Family]), Test = gproc:reg({p, l, Family}), erlang

How can a supervisor that reached_max_restart_intensity only delete the offending child?

流过昼夜 提交于 2019-12-24 02:59:13
问题 I have a one_for_one supervisor that handles similar and totally independent children. When there is a problem with one child, repeatedly crashing and triggering: =SUPERVISOR REPORT==== 30-Mar-2011::13:10:42 === Supervisor: {local,gateway_sup} Context: shutdown Reason: reached_max_restart_intensity Offender: [{pid,<0.76.0>}, ... shutting itself down and also terminating all the innocent children that would just continue to run fine otherwise. How can I build a supervision tree out of standard

How to use application:get_env() in Erlang/OTP?

浪尽此生 提交于 2019-12-24 01:08:32
问题 I created a mochiweb instance src/ |-- Makefile |-- room.erl |-- myserver.app |-- myserver.erl |-- myserver_app.erl |-- myserver_deps.erl |-- myserver_sup.erl |-- myserver_web.erl `-- uuid.erl in myserver_web.erl I am able to access the application config {ok, "0.0.1"} = application:get_key(vsn), However in room.erl , I am not able to access the application config (specifically the env list). undefined = application:get_key(vsn), The supervisor does not start the room, nor do I want it too. I

Not able to connect to a remote SSH server with Elixir

给你一囗甜甜゛ 提交于 2019-12-23 13:22:50
问题 I have been trying for a while to connect to a remote ssh server with elixir. This is what I do in IEX: [Macintosh] elixir/logglycious (master|…)> iex 15-07-20 0:11 Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> :application.start(:crypto) {:error, {:already_started, :crypto}} iex(2)> :application.start(:public_key) {:error, {:not_started, :asn1}} iex(3)>

Find length of Elixir/Erlang in-memory file?

我只是一个虾纸丫 提交于 2019-12-23 12:43:54
问题 In Elixir (or Erlang), if I have an in-memory file, how do I find its length in bytes? {:ok, fd} = :file.open("", [:ram, :read, :write]) :file.write(fd, "hello") 回答1: Not sure if there's a better way, but this is what I did: def get_length(fd) do {:ok, cur} = :file.position(fd, {:cur, 0}) try do :file.position(fd, {:eof, 0}) after :file.position(fd, cur) end end Usage: {:ok, fd} = :file.open("", [:ram, :read, :write]) :ok = :file.write(fd, "hello") {:ok, len} = get_length(fd) 回答2: You can use

How to restart child with custom state using Erlang OTP supervisor behaviour?

此生再无相见时 提交于 2019-12-23 07:59:40
问题 I'm using OTP supervisor behaviour to supervise and restart child processes. However when the child dies I want to restart it with the same state it had before the crash. If I write my own custom supervisor, I can just receive {EXIT,Pid,Reason} message and act upon it. When using OTP supervisor behaviour however it is all managed by OTP and I have no control over it. The only callback function I implement is init. Is there any standard approach in case like this? How to customise the state of

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

extending ejabberd with modules for custom mysql schema?

天涯浪子 提交于 2019-12-22 17:59:08
问题 Instead of ejabberd.sql,I am using a custom MySQL schema(because of legacy reasons). I will be doing some DB operations on certain activities like Ping,Pong,Msg deliverd,Msg read and most importantly getting/setting roster list and announcing presence(all of these on my own schema). However,ejabberd seems to use ejabberd.sql all throughout and its source code is pretty much dependent on it.Fiddling with the source code is the last thing I would do since I am not aware of its dependencies.

Why use OTP with erlang?

浪尽此生 提交于 2019-12-22 04:26:05
问题 As the question said: What benefits brings using the OTP design principles when developing with erlang? (I am developing a server which will just receive commands and send responses) 回答1: OTP is a battle-hardened set of design elements and idioms used in the creation of, as Jonas said, fault-tolerant systems among other things (like flexibility, live updates, etc.). In brief you want to use it for these environments, or environments that may grow into these, because a lot of the blood, sweat

Erlang : Disallowed Nodes / Maybe Cookie question

六月ゝ 毕业季﹏ 提交于 2019-12-22 01:53:59
问题 Trying to get two erlang nodes talking to each other : one on a Ubuntu machine and one on Windows XP. We're getting a " Connection attempt from disallowed node " message which prevents one node receiving messages from the other. They're both using 5.XXX versions of Erlang OTP. Both nodes have the same cookie ( .erlang.cookie) We are starting the receiver node with : erl -name fred@ipaddress and calling the function on it with 'fred@ipaddress' (in single quotes) We've turned firewalls off. So