Skip to content

Commit

Permalink
Add TODOs for plugin managment
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed May 21, 2024
1 parent b2887d9 commit b2d5e47
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 11 deletions.
41 changes: 40 additions & 1 deletion lib/plugins_management/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule MishkaInstaller.PluginsManagement.Event do
field(:priority, integer(), default: 100, derive: "validate(integer, min_len=0, max_len=100)")
# This type can be used when you want to introduce a status for an event.
field(:status, status(),
derive: "validate(enum=Atom[started::stopped::restarted])",
derive: "validate(enum=Atom[started::stopped::restarted::held])",
default: :started
)

Expand Down Expand Up @@ -95,6 +95,45 @@ defmodule MishkaInstaller.PluginsManagement.Event do
{:noreply, %{state | ref: nil}}
end

####################################################################################
######################### (▰˘◡˘▰) Functions (▰˘◡˘▰) ##########################
####################################################################################
def initialize() do
# TODO: create new module state
# TODO: we need some options like `event: event`, `module: module_name`, extension: extension
# |__ Check we need these options or not in this new version?
end

def restart() do
# TODO: restart all plugins of an event
# TODO: restart all plugins of all event
end

def stop() do
# TODO: stop all plugins of an event
# TODO: stop all plugins of all event
end

def get() do
end

def backup() do
# TODO: Create a json file of data
end

def restore() do
# TODO: create new module state when server is down and restart
# TODO: restore from json file
end

def purge() do
# TODO: purge all plugins of an event
# TODO: purge all plugins of all event
end

def ensure?() do
end

###################################################################################
############################ (▰˘◡˘▰) Query (▰˘◡˘▰) ##########################
###################################################################################
Expand Down
40 changes: 35 additions & 5 deletions lib/plugins_management/hook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,68 @@ defmodule MishkaInstaller.PluginsManagement.Hook do
@app_config Mix.Project.config()
@after_compile __MODULE__

# TODO: we need genserver
# TODO: we need handle_call to get info from genserver state
# |__ Like: dependent modules, status of this plug
def config(), do: @app_config

def config(key), do: Keyword.get(@app_config, key, nil)

def register() do
# TODO: Use Code.ensure_loaded to check developer event module
# TODO: Get parent module name(project name as atom)
# TODO: Check it is equele with extension params?
# TODO: Create and check this event name exist in db, it should be unique
# TODO: Change status to hold when dependency can not be found
# TODO: Send a request to enable all held plugin, when this plugin is their dependency
end

def start() do
# TODO: Check this module exist in db and change this status to started! expect held
# TODO: Create and re-create all plugins inside this event as a module state, read-only
# TODO: What we should do for dependency, if it has and they are not loaded!!
# |__ it can wait in this module Genserver, I mean custom plugin developer and try
# |__ with a timeout and a selected try
# |__ or it can subscribe to a pubsub and when the dependency is loaded.
# |__ it should be noted, it needs to listen to stop, and if it is hard depend; the
# |__ genserver should disable.
end

def restart() do
# TODO: It needs all start() has!
# TODO: For example user changes the database and want to re-creare it, based on our
# |__ requirements we need to get all plugins of this event and push to queue and create
# |__ the new module state
# TODO: Update at should be changed
# TODO: Change the status to restarted
# TODO: Send pubsub to other event, maybe this plugin is dependency to them
end

def stop() do
# TODO: Change plugin status
# TODO: Re-create event module state
# TODO: Send pubsub to other event, maybe this plugin is dependency to them
end

def delete() do
# TODO: After creating `installation_management` we can delete its project
#
# TODO: All unregister() does
end

def unregister() do
end

def ensure_event?() do
# TODO: Delete from Mnesia
# TODO: Re-create event module state
# TODO: Send pubsub to other event, maybe this plugin is dependency to them
# TODO: Send stop request to this plugin Genserver
end

defoverridable register: 0,
start: 0,
restart: 0,
stop: 0,
delete: 0,
unregister: 0,
ensure_event?: 0
unregister: 0

def __after_compile__(_env, _bytecode) do
unless Module.defines?(__MODULE__, {:call, 1}) do
Expand Down
11 changes: 6 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ defmodule MishkaInstaller.MixProject do
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:phoenix_pubsub, "~> 2.1"},
# Dev dependencies
{:ex_doc, "~> 0.32", only: :dev, runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},

# Extra tools
{:mishka_developer_tools, github: "mishka-group/mishka_developer_tools"}
{:mishka_developer_tools, github: "mishka-group/mishka_developer_tools"},

# Dev dependencies
{:ex_doc, "~> 0.32.2", only: :dev, runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
]
end

Expand Down

0 comments on commit b2d5e47

Please sign in to comment.