-
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.
start implementing Genstage server for producing outline events
- Loading branch information
1 parent
2294c2a
commit 3f0f00b
Showing
6 changed files
with
70 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,16 @@ | ||
defmodule Radiator.Outline.Event do | ||
Check warning on line 1 in lib/radiator/outline/event.ex GitHub Actions / Build & Test
|
||
alias Radiator.Outline.EventProducer | ||
|
||
def build(event_id, event_type, user_id, payload) do | ||
%{ | ||
event_id: event_id, | ||
event_type: event_type, | ||
user_id: user_id, | ||
payload: payload | ||
} | ||
end | ||
|
||
def enqueue(event) do | ||
EventProducer.enqueue(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Radiator.Outline.EventProducer do | ||
Check warning on line 1 in lib/radiator/outline/event_producer.ex GitHub Actions / Build & Test
|
||
use GenStage | ||
|
||
def start_link(opts \\ []) do | ||
GenStage.start_link(__MODULE__, opts, name: __MODULE__) | ||
end | ||
|
||
def init(_opts) do | ||
{:producer, []} | ||
end | ||
|
||
def enqueue(event) do | ||
GenStage.cast(__MODULE__, {:enqueue, event}) | ||
:ok | ||
end | ||
|
||
def handle_cast({:enqueue, event}, state) do | ||
{:noreply, [event], state} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Radiator.Outline.Server do | ||
Check warning on line 1 in lib/radiator/outline/server.ex GitHub Actions / Build & Test
|
||
alias Radiator.Outline.Event | ||
|
||
def insert_node(attributes, user_id, event_id) do | ||
"insert_node" | ||
|> Event.build(attributes, user_id, event_id) | ||
|> Event.enqueue() | ||
|
||
# generate event | ||
# send to Eventserver | ||
# validate | ||
# true-> | ||
# database action: insert node() | ||
# create && persist event (event contains all attributes, user, event_id, timestamps) | ||
# broadcast event (topic: episode_id) | ||
# broadcast node (topic: episode_id) | ||
# false-> | ||
# log error and return error (audit log) | ||
:ok | ||
end | ||
|
||
# TODO | ||
# update_node | ||
# delete_node | ||
# move_node | ||
|
||
# list_node different case, sync call | ||
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
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