Skip to content

Commit

Permalink
Add stop all plugin of an event and all events
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed May 26, 2024
1 parent ad7ad61 commit 8ea8be4
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/plugins_management/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,38 @@ defmodule MishkaInstaller.PluginsManagement.Event do
end

def stop(event) do
event
# TODO: stop all plugins of an event
case read(event: event) do
{:error, error} ->
{:error, error}

data ->
data
|> Enum.each(fn pl_item ->
with :ok <- plugin_status(pl_item.status),
{:ok, db_plg} <- update(:status, :stopped, pl_item.id),
plugins when is_list(plugins) <- read(event: event),
:ok <- MishkaInstaller.broadcast("event", :stop, db_plg, true) do
{:ok, :stop, db_plg}
end
end)

sorted_plugins =
Enum.reject(data, &(&1.status in [:stopped, :held]))
|> Enum.sort_by(&{&1.priority, &1.name})

PluginModuleStateEvent.purge_create(sorted_plugins, event)
end
end

def stop() do
# TODO: stop all plugins of all event
case group_events() do
{:ok, events} ->
Enum.each(events, &stop(&1))
:ok

error ->
error
end
end

def unregister(name, event, broadcast) do
Expand Down

0 comments on commit 8ea8be4

Please sign in to comment.