-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-architecture of Alice's supervision tree structure #85
base: a2
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Alice.Adapter.Supervisor do | ||
@moduledoc """ | ||
Supervises any Alice.Adapter process that are started. | ||
""" | ||
|
||
use Supervisor | ||
|
||
def start_link(_) do | ||
Supervisor.start_link([ | ||
worker(Alice.Adapter, [], restart: :transient) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to consider converting this to a module based supervisor, [per the docs here] (https://hexdocs.pm/elixir/Supervisor.html#module-module-based-supervisors) particularly since this is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I wasn't doing anything in |
||
], strategy: :simple_one_for_one, name: __MODULE__) | ||
end | ||
|
||
def init(_), do: :ok | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
defmodule Alice.Bot.Supervisor do | ||
@moduledoc false | ||
@moduledoc """ | ||
Supervises any Alice.Bot process that are started. | ||
""" | ||
|
||
use Supervisor | ||
|
||
def start_link(opts \\ []) do | ||
Supervisor.start_link(__MODULE__, :ok, opts) | ||
def start_link(_) do | ||
Supervisor.start_link([ | ||
worker(Alice.Bot, [], restart: :transient) | ||
], strategy: :simple_one_for_one, name: __MODULE__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here about going with a module based supervisor. I also don't think we need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it SOFO because the bot process is started by the user's bot project after the entire Alice tree starts. Using SOFO, we don't have to double-supervise the bot process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, having said that, I'm not 100% happy with having to start the bot there kind of manually, so maybe that's something we still have to figure out. |
||
end | ||
|
||
def init(:ok) do | ||
[worker(Alice.Bot, [], restart: :transient)] | ||
|> supervise(strategy: :simple_one_for_one) | ||
end | ||
def init(_), do: :ok | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
defmodule Alice.Handler.Supervisor do | ||
def start_link do | ||
import Supervisor.Spec, warn: false | ||
@moduledoc """ | ||
Supervises any Alice.Handler process that are started. | ||
""" | ||
|
||
children = [ | ||
use Supervisor | ||
|
||
def start_link(_) do | ||
Supervisor.start_link([ | ||
worker(Alice.Handler, [], restart: :transient) | ||
] | ||
Supervisor.start_link(children, strategy: :simple_one_for_one) | ||
], strategy: :simple_one_for_one, name: __MODULE__) | ||
end | ||
|
||
def init(_), do: :ok | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
defmodule Alice.Supervisor do | ||
@moduledoc false | ||
@moduledoc """ | ||
The main Supervisor in an Alice bot's hierarchy. Starts | ||
and supervises the Bot, Handler, and Adapter supervisors. | ||
""" | ||
|
||
use Supervisor | ||
|
||
def start_link do | ||
Supervisor.start_link(__MODULE__, :ok, name: __MODULE__) | ||
Supervisor.start_link([ | ||
Alice.Adapter.Supervisor, | ||
Alice.Handler.Supervisor, | ||
Alice.Bot.Supervisor, | ||
], strategy: :one_for_one, name: __MODULE__) | ||
end | ||
|
||
def init(:ok) do | ||
children = [ | ||
supervisor(Alice.Bot.Supervisor, [[name: Alice.Bot.Supervisor]]), | ||
] | ||
|
||
supervise(children, strategy: :one_for_one) | ||
end | ||
def init(_), do: :ok | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processes
instead ofprocess
. 😃There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍