-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f0f00b
commit 36395ce
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Radiator.Outline.EventConsumer do | ||
use GenStage | ||
alias Radiator.Outline.EventProducer | ||
|
||
def start_link(opts \\ []) do | ||
GenStage.start_link(__MODULE__, opts, name: __MODULE__) | ||
end | ||
|
||
def init(_opts) do | ||
options = [] | ||
{:consumer, :event_producer, subscribe_to: [{EventProducer, options}]} | ||
end | ||
|
||
def handle_events(events, _from, state) do | ||
IO.inspect(events, label: "EventConsumer handle_events") | ||
|
||
Enum.each(events, fn event -> | ||
process_event(event, state) | ||
IO.inspect(event, label: "EventConsumer handle_events event") | ||
end) | ||
|
||
{:noreply, [], state} | ||
end | ||
|
||
defp process_event(%InsertNodeEvent{} = event) do | ||
# validate | ||
# true-> | ||
# database action: insert node() | ||
# create && persist event (event contains all attributes, user, event_id, timestamps) | ||
# broadcast event (topic: episode_id) | ||
# false-> | ||
# log error and return error (audit log) | ||
end | ||
|
||
defp handle_result(:ok, event) do | ||
persist_event(event) | ||
broadcast_success(event) | ||
end | ||
|
||
defp handle_result(:error, event) do | ||
broadcast_error(event) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters