8000 Featurer/dispatcher by Zurga · Pull Request #3 · Zurga/ecto_watch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Featurer/dispatcher #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ecto_watch/options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ defmodule EctoWatch.Options do

alias EctoWatch.Options.WatcherOptions

defstruct [:repo_mod, :pub_sub_mod, :watchers, :debug?]
defstruct [:repo_mod, :pub_sub_mod, :dispatcher, :watchers, :debug?]

def new(opts) do
%__MODULE__{
repo_mod: opts[:repo],
pub_sub_mod: opts[:pub_sub],
dispatcher: opts[:dispatcher],
watchers:
Enum.map(opts[:watchers], fn watcher_opts ->
WatcherOptions.new(watcher_opts, opts[:debug?])
Expand All @@ -26,6 +27,7 @@ defmodule EctoWatch.Options do
type: {:custom, __MODULE__, :check_valid_pubsub_module, []},
required: true
],
dispatcher: [type: :atom, required: false, default: Phoenix.PubSub],
watchers: [
type: {:custom, WatcherOptions, :validate_list, []},
required: true
Expand Down
9 changes: 5 additions & 4 deletions lib/ecto_watch/watcher_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ defmodule EctoWatch.WatcherServer do
end
end

def start_link({repo_mod, pub_sub_mod, watcher_options}) do
def start_link({repo_mod, pub_sub_mod, dispatcher, watcher_options}) do
GenServer.start_link(
__MODULE__,
{repo_mod, pub_sub_mod, watcher_options},
{repo_mod, pub_sub_mod, dispatcher, watcher_options},
name: unique_label(watcher_options)
)
end

@impl true
def init({repo_mod, pub_sub_mod, options}) do
def init({repo_mod, pub_sub_mod, dispatcher, options}) do
debug_log(options, "Starting server")

unique_label = "#{unique_label(options)}"
Expand Down Expand Up @@ -121,6 +121,7 @@ defmodule EctoWatch.WatcherServer do
%{
repo_mod: repo_mod,
pub_sub_mod: pub_sub_mod,
dispatcher: dispatcher,
unique_label: unique_label,
identifier_columns:
MapSet.put(
Expand Down Expand Up @@ -226,7 +227,7 @@ defmodule EctoWatch.WatcherServer do
"Broadcasting to Phoenix PubSub topic `#{topic}`: #{inspect(message)}"
)

Phoenix.PubSub.broadcast(state.pub_sub_mod, topic, message)
Phoenix.PubSub.broadcast(state.pub_sub_mod, topic, message, state.dispatcher)
end

{:noreply, state}
Expand Down
2 changes: 1 addition & 1 deletion lib/ecto_watch/watcher_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule EctoWatch.WatcherSupervisor do
id: WatcherServer.name(watcher_options),
start:
{WatcherServer, :start_link,
[{options.repo_mod, options.pub_sub_mod, watcher_options}]}
[{options.repo_mod, options.pub_sub_mod, options.dispatcher, watcher_options}]}
}
end)

Expand Down
0