Skip to content

Commit

Permalink
chg: [source] restart source on config update
Browse files Browse the repository at this point in the history
  • Loading branch information
gallypette committed Oct 14, 2024
1 parent e65d8c1 commit c1a9c05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
49 changes: 17 additions & 32 deletions lib/cocktailparty/catalog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -240,40 +240,25 @@ defmodule Cocktailparty.Catalog do
def update_source(%Source{} = source, attrs) do
changeset = change_source(source, attrs)

# Preserve the existing users association
changeset = Ecto.Changeset.put_assoc(changeset, :users, source.users)
# TODO
# remove broker logic -- call the source itself

case changeset do
%Ecto.Changeset{
changes: %{channel: new_channel},
data: %Source{} = source
}
when source.channel != new_channel ->
# We ask the broker to delete the source with the old channel
# TODO Terminate the source gen_server
# notify_broker(source, {:delete_source, source})
# We notify the monitor
notify_monitor({:unsubscribe, "feed:" <> Integer.to_string(source.id)})

# We update the source
{:ok, source} =
changeset
|> validate_source_type()
|> Repo.update()

# And we ask the broker and the pubsubmonitor to subscribe to the updated source
# TODO Create a new source gen_server
# notify_broker(source, {:new_source, source})
notify_monitor({:subscribe, "feed:" <> Integer.to_string(source.id)})

{:ok, source}

_ ->
if changed?(changeset, :config) do
source =
changeset
|> validate_source_type()
|> Repo.update()

case Repo.update(source) do
{:ok, source} ->
notify_monitor({:unsubscribe, "feed:" <> Integer.to_string(source.id)})
SourceManager.restart_source(source.id)
notify_monitor({:subscribe, "feed:" <> Integer.to_string(source.id)})
{:ok, source}

{:error, changeset} ->
{:error, changeset}
end
else
changeset
|> validate_source_type()
|> Repo.update()
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/cocktailparty/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ defmodule Cocktailparty.Input do
Connection.terminate(connection)
{:ok, connection} = Repo.update(changeset)
ConnectionManager.start_connection(connection)
# TODO restart corresponding sources
# get the full object
conn = get_connection!(connection.id)
Enum.map(conn.sources, fn x ->
Expand Down

0 comments on commit c1a9c05

Please sign in to comment.