-
Notifications
You must be signed in to change notification settings - Fork 39
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
Refactor code related to crash groups and linking mechanism #574
Conversation
a389db0
to
95b5d23
Compare
95b5d23
to
233b0d2
Compare
92e500a
to
ed3c26f
Compare
ed3c26f
to
809f17f
Compare
@@ -653,45 +653,32 @@ defmodule Membrane.Core.Parent.ChildLifeController do | |||
end | |||
|
|||
defp do_handle_child_death(child_name, :normal, state) do |
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.
this and the next clause became quite similar, I'd consider merging them
lib/membrane/core/parent/child_life_controller/crash_group_utils.ex
Outdated
Show resolved
Hide resolved
|
||
@spec handle_crash_group_member_death(Child.name(), CrashGroup.t(), any(), Parent.state()) :: | ||
Parent.state() | ||
def handle_crash_group_member_death(child_name, crash_group_data, reason, state) |
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.
this has so many clauses, can we make it a bit less verbose?
defp merge_pad_direction_data(pad_data, metadata, state) do | ||
merge_pad_data(pad_data, &init_pad_direction_data(&1, metadata, state)) | ||
end | ||
|
||
defp merge_pad_mode_data(pad_data, props, other_info, state) do | ||
merge_pad_data(pad_data, &init_pad_mode_data(&1, props, other_info, state)) | ||
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.
These add another level of complexity, which is one level too much IMO. If you don't like passing a function to merge_pad_data
, I'd rather remove it and rename each init_pad_*_data
function to merge_pad_*_data
and explicitly call Map.merge
there.
acef791
to
cfa54e8
Compare
cf3ab1b
to
d3a16ea
Compare
if pad_info.direction != :input, | ||
do: raise("pad direction #{inspect(pad_info.direction)} is wrong") |
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.
is it even possible? If so, why don't we move it to the pattern match?
@@ -137,17 +130,18 @@ defmodule Membrane.Core.Element.PadController do | |||
end | |||
end | |||
|
|||
defp do_handle_link(:input, endpoint, other_endpoint, info, link_props, state) do | |||
defp do_handle_link(:input, endpoint, other_endpoint, pad_info, link_props, state) do |
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.
perhaps we could "resolve" the names (endpoint
-> input_endpoint
etc.)?
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.
the same applies for the do_handle_link(:output, ...)
state = | ||
state.pads_data | ||
|> Map.values() | ||
|> Enum.filter(&(&1.direction != data.direction and &1.flow_control == :auto)) | ||
|> Enum.reduce(state, fn other_data, state -> | ||
PadModel.update_data!(state, other_data.ref, :associated_pads, &[data.ref | &1]) | ||
|> Enum.filter(&(&1.direction != pad_data.direction and &1.flow_control == :auto)) | ||
|> Enum.reduce(state, fn opposite_pad_data, state -> | ||
PadModel.update_data!( | ||
state, | ||
opposite_pad_data.ref, | ||
:associated_pads, | ||
&[pad_data.ref | &1] | ||
) |
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.
[NIT] I would opt for moving that part of code to some separate function, e.g. update_associated_pads
or something like that.
|
||
# adding crash group to state | ||
state = | ||
if options.crash_group_mode != nil do | ||
if options.crash_group_mode != nil or Map.has_key?(state.crash_groups, options.group) do |
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.
I am not sure I get it - shouldn't it be: if options.crash_group_mode != nil and (not Map.has_key?(state.crash_groups, options.group))
?
end | ||
end | ||
|
||
defp trigger_crash_group(crash_initiator, %CrashGroup{} = group, state) do |
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.
I am not the biggest fan of the trigger_crash_group
name - I would opt at least for trigger_crash_group_crash
, but it might sound funny :D
Perhaps you have some better alternative?
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.
and when it comes to triggered?
- I would rename it to crash_triggered?
or something like that
d7d57aa
to
332a724
Compare
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.
Looks good 👍
test/membrane/core/element_test.exs
Outdated
@@ -130,10 +130,10 @@ defmodule Membrane.Core.ElementTest do | |||
%Endpoint{pad_spec: :output, pad_ref: :output, pad_props: %{options: []}, child: :this}, | |||
output_other_endpoint, | |||
%{ | |||
other_info: other_info, | |||
# other_info: other_info, |
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.
;)
[Child.name()], | ||
Parent.state() | ||
) :: Parent.state() | ||
def extend_crash_group(group_name, _mode, children, state) do |
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.
I would remove mode
argument here
def extend_crash_group(group_name, _mode, children, state) do | |
def extend_crash_group(group_name, children, state) do |
Related Jira ticekt: https://membraneframework.atlassian.net/browse/MC-191