Skip to content

Commit

Permalink
Add :reason to the ctx in handle_crash_group_down
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikWolek committed Jan 24, 2024
1 parent 5c2a831 commit 7c85a47
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/membrane/bin/callback_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ defmodule Membrane.Bin.CallbackContext do
Field `:start_of_stream_received?` is present only in
`c:Membrane.Bin.handle_element_end_of_stream/4`.
Fields `:members` and `:crash_initiator` are present only in
`c:Membrane.Pipeline.handle_crash_group_down/3`.
Fields `:members`, `:crash_initiator` and `reason` and are present only in
`c:Membrane.Bin.handle_crash_group_down/3`.
"""
@type t :: %{
:clock => Membrane.Clock.t(),
Expand All @@ -27,6 +27,7 @@ defmodule Membrane.Bin.CallbackContext do
optional(:pad_options) => map(),
optional(:members) => [Membrane.Child.name()],
optional(:crash_initiator) => Membrane.Child.name(),
optional(:reason) => Membrane.Core.Parent.CrashGroup.reason(),
optional(:start_of_stream_received?) => boolean()
}
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,27 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
end
end

def handle_crash_group_member_death(child_name, %CrashGroup{} = group, _reason, state) do
def handle_crash_group_member_death(
child_name,
%CrashGroup{} = group,
{:shutdown, :membrane_crash_group_kill},
state
) do
handle_non_normal_member_death(child_name, group, state)
end

def handle_crash_group_member_death(child_name, %CrashGroup{} = group, reason, state) do
state =
update_in(
state,
[:crash_groups, group.name],
&%CrashGroup{&1 | reason: reason}
)

handle_non_normal_member_death(child_name, group, state)
end

defp handle_non_normal_member_death(child_name, group, state) do
state =
if group.detonating? do
state
Expand Down Expand Up @@ -108,7 +128,8 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
context_generator =
&Component.context_from_state(&1,
members: crash_group.members,
crash_initiator: crash_group.crash_initiator
crash_initiator: crash_group.crash_initiator,
reason: crash_group.reason
)

CallbackHandler.exec_and_handle_callback(
Expand Down
8 changes: 6 additions & 2 deletions lib/membrane/core/parent/crash_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ defmodule Membrane.Core.Parent.CrashGroup do
# * name - name that identifies the group
# * type - responsible for restart policy of members of groups
# * members - list of members of group
# * reason - reason of the crash

use Bunch.Access

@type name() :: any()
@type reason() :: any()

@type t :: %__MODULE__{
name: name(),
mode: :temporary,
members: [Membrane.Child.name()],
detonating?: boolean(),
crash_initiator: Membrane.Child.name()
crash_initiator: Membrane.Child.name(),
reason: reason()
}

@enforce_keys [:name, :mode]
defstruct @enforce_keys ++ [members: [], detonating?: false, crash_initiator: nil]
defstruct @enforce_keys ++
[members: [], detonating?: false, crash_initiator: nil, reason: :normal]
end
3 changes: 2 additions & 1 deletion lib/membrane/pipeline/callback_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Membrane.Pipeline.CallbackContext do
Field `:start_of_stream_received?` is present only in
`c:Membrane.Pipeline.handle_element_end_of_stream/4`.
Fields `:members` and `:crash_initiator` are present only in
Fields `:members`, `:crash_initiator` and `:reason` are present only in
`c:Membrane.Pipeline.handle_crash_group_down/3`.
"""
@type t :: %{
Expand All @@ -23,6 +23,7 @@ defmodule Membrane.Pipeline.CallbackContext do
optional(:from) => [GenServer.from()],
optional(:members) => [Membrane.Child.name()],
optional(:crash_initiator) => Membrane.Child.name(),
optional(:reason) => Membrane.Core.Parent.CrashGroup.reason(),
optional(:start_of_stream_received?) => boolean()
}
end

0 comments on commit 7c85a47

Please sign in to comment.