Skip to content

Commit

Permalink
Add start an event and events, re-start
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed May 26, 2024
1 parent 8ea8be4 commit 043b59d
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions lib/plugins_management/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,38 @@ defmodule MishkaInstaller.PluginsManagement.Event do
end

def start(event) do
event
# TODO: start 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 <- hold_statuses?(pl_item.depends),
{:ok, db_plg} <- update(:status, :started, pl_item.id),
:ok <- MishkaInstaller.broadcast("event", :start, pl_item, 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 start() do
# TODO: start all plugins of all event
case group_events() do
{:ok, events} ->
Enum.each(events, &start(&1))
:ok

error ->
error
end
end

def restart(name, broadcast) do
Expand All @@ -141,12 +167,38 @@ defmodule MishkaInstaller.PluginsManagement.Event do
end

def restart(event) do
event
# TODO: restart 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, :start, start_data} <- pl_item.name.start(false),
{:ok, db_plg} <- update(:status, :restarted, start_data.id),
:ok <- MishkaInstaller.broadcast("event", :restart, 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 restart() do
# TODO: restart all plugins of all event
case group_events() do
{:ok, events} ->
Enum.each(events, &restart(&1))
:ok

error ->
error
end
end

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

0 comments on commit 043b59d

Please sign in to comment.