Created
February 3, 2016 18:18
-
-
Save neektza/572891715e978ee9d7b8 to your computer and use it in GitHub Desktop.
Confused?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MessageSpammer.Connector do | |
use Supervisor | |
def start_link do | |
Supervisor.start_link(__MODULE__, []) | |
end | |
def init(_) do | |
IO.puts "Starting Connector" | |
clients = spawn_clients([], 100) | |
IO.inspect clients | |
spammer = worker(MessageSpammer.Spammer, [{:interval, 1, :pids, clients}], restart: :temporary) | |
Supervisor.start_link([spammer], [strategy: :one_for_one, name: MessageSpammer.Supervisor]) # WORKS | |
supervise([spammer], strategy: :simple_one_for_one) # DOESNT WORK | |
end | |
def spawn_clients(pids, cnt) do | |
l = length(pids) + 1 | |
if l < cnt do | |
{ :ok, client_pid } = MessageSpammer.Client.start_link(%{}) | |
MessageSpammer.Client.connect(client_pid, [client_id: "client-#{l}", host: "localhost", port: 1883]) | |
spawn_clients(pids ++ [client_pid], cnt) | |
else | |
pids | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment