1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.FedSockets.Supervisor do
9 def start_link(opts) do
10 Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
15 build_cache(:fed_socket_fetches, args),
16 build_cache(:fed_socket_rejections, args),
17 {Registry, keys: :unique, name: FedSockets.Registry, meta: [rejected: %{}]}
20 opts = [strategy: :one_for_all, name: Pleroma.Web.Streamer.Supervisor]
21 Supervisor.init(children, opts)
24 defp build_cache(name, args) do
25 opts = get_opts(name, args)
28 id: String.to_atom("#{name}_cache"),
29 start: {Cachex, :start_link, [name, opts]},
34 defp get_opts(cache_name, args)
35 when cache_name in [:fed_socket_fetches, :fed_socket_rejections] do
36 default = get_opts_or_config(args, cache_name, :default, 15_000)
37 interval = get_opts_or_config(args, cache_name, :interval, 3_000)
38 lazy = get_opts_or_config(args, cache_name, :lazy, false)
40 [expiration: expiration(default: default, interval: interval, lazy: lazy)]
43 defp get_opts(name, args) do
44 Keyword.get(args, name, [])
47 defp get_opts_or_config(args, name, key, default) do
49 |> Keyword.get(name, [])
53 Pleroma.Config.get([:fed_sockets, name, key], default)