Skip to content

Commit

Permalink
Refactor subscribing to stack events
Browse files Browse the repository at this point in the history
  • Loading branch information
msfstef committed Nov 21, 2024
1 parent 41ae9a6 commit a2597da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sync-service/lib/electric/plug/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule Electric.Plug.Utils do
stack_events_registry = conn.assigns.config[:stack_events_registry]

ref = make_ref()
Registry.register(stack_events_registry, {:stack_status, stack_id}, ref)
Electric.StackSupervisor.subscribe_to_stack_events(stack_events_registry, stack_id, ref)

if Electric.ProcessRegistry.alive?(stack_id, Electric.Replication.Supervisor) do
conn
Expand Down
4 changes: 4 additions & 0 deletions packages/sync-service/lib/electric/stack_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ defmodule Electric.StackSupervisor do
end
end

def subscribe_to_stack_events(registry, stack_id, value) do
Registry.register(registry, {:stack_status, stack_id}, value)
end

def dispatch_stack_event(registry, stack_id, event) do
Registry.dispatch(registry, {:stack_status, stack_id}, fn entries ->
for {pid, ref} <- entries do
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-service/test/support/component_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ defmodule Support.ComponentSetup do
stack_events_registry = Registry.StackEvents

ref = make_ref()
Registry.register(stack_events_registry, {:stack_status, stack_id}, ref)
Electric.StackSupervisor.subscribe_to_stack_events(stack_events_registry, stack_id, ref)

stack_supervisor =
start_supervised!(
Expand Down

0 comments on commit a2597da

Please sign in to comment.