start gun upload pool, if proxy_remote is enabled
[akkoma] / lib / pleroma / pool / supervisor.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Pool.Supervisor do
6 use Supervisor
7
8 alias Pleroma.Config
9 alias Pleroma.Pool
10
11 def start_link(args) do
12 Supervisor.start_link(__MODULE__, args, name: __MODULE__)
13 end
14
15 def init(_) do
16 children =
17 [
18 %{
19 id: Pool.Connections,
20 start:
21 {Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]}
22 }
23 ] ++ pools()
24
25 Supervisor.init(children, strategy: :one_for_one)
26 end
27
28 defp pools do
29 pools = Config.get(:pools)
30
31 pools =
32 if Config.get([Pleroma.Upload, :proxy_remote]) == false do
33 Keyword.delete(pools, :upload)
34 else
35 pools
36 end
37
38 for {pool_name, pool_opts} <- pools do
39 pool_opts
40 |> Keyword.put(:id, {Pool, pool_name})
41 |> Keyword.put(:name, pool_name)
42 |> Pool.child_spec()
43 end
44 end
45 end