Update/fix Omnibot.Irc.route_msg/2 to spawn a new task for each module, instead of a single task for all modules
Previously, if a message was supposed to be handled by 3 modules, they would all be handled, synchronously, in the same process. If any of them crashed, it would affect any other modules that needed to be processed ahead of it. Now, a new task is spun up for each module, so module handlers are now indpendent. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
15
lib/irc.ex
15
lib/irc.ex
@@ -30,8 +30,15 @@ defmodule Omnibot.Irc do
|
||||
|
||||
defp route_msg(irc, msg) do
|
||||
channel = Msg.channel(msg)
|
||||
|
||||
State.channel_modules(channel)
|
||||
|> Enum.each(fn {module, _} -> module.on_msg(irc, msg) end)
|
||||
|> Enum.each(fn {module, _} ->
|
||||
# Create a new task for each module
|
||||
{:ok, _task} = Task.Supervisor.start_child(
|
||||
Omnibot.RouterSupervisor,
|
||||
fn -> module.on_msg(irc, msg) end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
## Server callbacks
|
||||
@@ -76,11 +83,7 @@ defmodule Omnibot.Irc do
|
||||
msg = Msg.parse(line)
|
||||
|
||||
# Send the message to the router
|
||||
irc = self()
|
||||
{:ok, _task} = Task.Supervisor.start_child(
|
||||
Omnibot.RouterSupervisor,
|
||||
fn -> route_msg(irc, msg) end
|
||||
)
|
||||
route_msg(self(), msg)
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user