supervisor.ex 790 Bytes
Newer Older
Steven Fuchs's avatar
Steven Fuchs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
defmodule Pleroma.Web.Streamer.Supervisor do
  use Supervisor

  def start_link(opts) do
    Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
  end

  def init(args) do
    children = [
      {Pleroma.Web.Streamer.State, args},
      {Pleroma.Web.Streamer.Ping, args},
      :poolboy.child_spec(:streamer_worker, poolboy_config())
    ]

    opts = [strategy: :one_for_one, name: Pleroma.Web.Streamer.Supervisor]
    Supervisor.init(children, opts)
  end

  defp poolboy_config do
    opts =
      Pleroma.Config.get(:streamer,
        workers: 3,
        overflow_workers: 2
      )

    [
      {:name, {:local, :streamer_worker}},
      {:worker_module, Pleroma.Web.Streamer.Worker},
      {:size, opts[:workers]},
      {:max_overflow, opts[:overflow_workers]}
    ]
  end
end