diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-12-05 20:18:25 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-12-05 20:18:25 +0700 |
commit | 48ae3c4347f68e20db7e3e67da32be2e70599fb3 (patch) | |
tree | 1179b632f65d1488825e0321d205ce43f90ad226 /lib | |
parent | 7722e5a67a46304f3ae0e37f674a44ca9268be5e (diff) | |
download | pleroma-48ae3c4347f68e20db7e3e67da32be2e70599fb3.tar.gz |
Add support for custom modules
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/application.ex | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 9dbd1e26b..5b6e233a6 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -32,6 +32,7 @@ defmodule Pleroma.Application do def start(_type, _args) do Pleroma.Config.DeprecationWarnings.warn() setup_instrumenters() + load_custom_modules() # Define workers and child supervisors to be supervised children = @@ -67,6 +68,29 @@ defmodule Pleroma.Application do Supervisor.start_link(children, opts) end + def load_custom_modules() do + dir = Pleroma.Config.get([:instance, :custom_modules_dir]) + + if dir && File.exists?(dir) do + dir + |> File.ls!() + |> Enum.map(&Path.join(dir, &1)) + |> Kernel.ParallelCompiler.compile() + |> case do + {:error, _errors, _warnings} -> + raise "Invalid custom modules" + + {:ok, modules, _warnings} -> + Enum.each(modules, fn mod -> + name = mod |> Atom.to_string() |> String.trim_leading("Elixir.") + IO.puts("Custom module loaded: #{name}") + end) + + :ok + end + end + end + defp setup_instrumenters do require Prometheus.Registry |