Skip to content

Commit

Permalink
add NodeChangeListener
Browse files Browse the repository at this point in the history
that listens to change events of nodes
  • Loading branch information
electronicbites committed Sep 1, 2024
1 parent 84d0b1d commit c59128e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/radiator/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Radiator.Application do

alias Radiator.Outline.CommandProcessor
alias Radiator.Outline.EventProducer
alias Radiator.Outline.NodeChangeListener

@impl true
def start(_type, _args) do
Expand All @@ -22,7 +23,8 @@ defmodule Radiator.Application do
# Start to serve requests, typically the last entry
RadiatorWeb.Endpoint,
{EventProducer, name: EventProducer},
{CommandProcessor, name: CommandProcessor, subscribe_to: [{EventProducer, max_demand: 1}]}
{CommandProcessor, name: CommandProcessor, subscribe_to: [{EventProducer, max_demand: 1}]},
{NodeChangeListener, name: NodeChangeListener}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
33 changes: 33 additions & 0 deletions lib/radiator/outline/node_change_listener.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Radiator.Outline.NodeChangeListener do
@moduledoc """
Genserver that listens to change events and starts jobs
It is an eventconsumer that listens to changes in the outline and starts workers
"""
use GenServer
alias Radiator.Outline.Dispatch

def start_link(_) do
GenServer.start_link(__MODULE__, :ok, [])
end

def init(_) do
Dispatch.subscribe()
{:ok, []}
end

def handle_info(%Radiator.Outline.Event.NodeContentChangedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeInsertedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeMovedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeDeletedEvent{} = _event, state) do
{:noreply, state}
end
end

0 comments on commit c59128e

Please sign in to comment.