Skip to content
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

Draft
wants to merge 2 commits into
base: a2
Choose a base branch
from

Conversation

adamzaninovich
Copy link
Member

@adamzaninovich adamzaninovich commented Sep 12, 2017

Tests are passing now

This change restructures the OTP supervision tree of the Alice application. You can now have multiple adapters. Also, your Bot process is inserted into the main Alice supervision tree without the need to double-supervise it in your bot application.

Before

nonode_nohost

After

screen shot 2017-09-12 at 1 22 18 am

@adamzaninovich adamzaninovich changed the title it runs with multiple adapters but tests need fixing WIP: Re-architecture of Alice's supervision tree structure Sep 12, 2017
@adamzaninovich adamzaninovich modified the milestone: Alice 2 Sep 12, 2017
@adamzaninovich adamzaninovich changed the title WIP: Re-architecture of Alice's supervision tree structure Re-architecture of Alice's supervision tree structure Sep 13, 2017
mattr-
mattr- previously requested changes Sep 14, 2017
Copy link
Contributor

@mattr- mattr- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few non-major comments.

@@ -0,0 +1,15 @@
defmodule Alice.Adapter.Supervisor do
@moduledoc """
Supervises any Alice.Adapter process that are started.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processes instead of process. 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if Process.alive?(pid) do
%{adapters: adapters, handlers: handlers} = :sys.get_state(pid)
for adapter <- adapters do
Supervisor.terminate_child(Alice.Adapter.Supervisor, Process.whereis(adapter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Supervisor.stop (docs here) with Alice.Adapter.Supervisorbe used to avoid the loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into it, that would be much better. This is what I had to do to get rid of that error messages after the tests run, and I'm all for simplifying it.

Supervisor.terminate_child(Alice.Adapter.Supervisor, Process.whereis(adapter))
end
for handler <- handlers do
Supervisor.terminate_child(Alice.Handler.Supervisor, Process.whereis(handler))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question here for the handler supervisor.


def start_link(_) do
Supervisor.start_link([
worker(Alice.Adapter, [], restart: :transient)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 simple_one_for_one supervisor. This will be important in particular if we want to support hot code-reloading as a deployment strategy (and I think we do). This change seems pretty simple, as it means moving most things to the init/1 callback rather than start_link/2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I wasn't doing anything in init for now I used the simplified version, but I think you're right. It will leave it more open for change and doesn't add much, if any, extra complexity.

def start_link(_) do
Supervisor.start_link([
worker(Alice.Bot, [], restart: :transient)
], strategy: :simple_one_for_one, name: __MODULE__)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 simple_one_for_one supervisor here. We may have discussed why a straight one_to_one wouldn't work, but i don't remember why that is.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@mattr-
Copy link
Contributor

mattr- commented Sep 14, 2017

I feel like all the process manipulation you're doing in the test is indicative of a larger problem in the setup of the supervision trees. Perhaps it's just a thing where the tests need to run synchronously. Either way, that process manipulation feels like a smell but I also don't have a good way to counteract it ATM, so it might as well stay for now.

@adamzaninovich
Copy link
Member Author

@mattr- thanks for the review!

I agree about the process manipulation for the tests. It feels a bit dirty. I think I'm ok with A2 being rough around the edges in general at this stage as long as we're mindful about improving as we iterate on it before release. I feel pretty confident that we can find ways to keep improving this.

@mattr-
Copy link
Contributor

mattr- commented Sep 14, 2017

I feel pretty confident that we can find ways to keep improving this.

Same. I just wanted to make sure I said something about it explicitly vs. letting it rot away. 😃

@mattr- mattr- dismissed their stale review October 16, 2018 18:51

old review

@adamzaninovich adamzaninovich marked this pull request as draft April 11, 2020 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants