application.ex 2.57 KB
Newer Older
lain's avatar
lain committed
1
2
defmodule Pleroma.Application do
  use Application
href's avatar
href committed
3
  import Supervisor.Spec
lain's avatar
lain committed
4

href's avatar
href committed
5
6
7
8
9
10
  @name "Pleroma"
  @version Mix.Project.config()[:version]
  def name, do: @name
  def version, do: @version
  def named_version(), do: @name <> " " <> @version

href's avatar
href committed
11
12
13
14
15
  def user_agent() do
    info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
    named_version() <> "; " <> info
  end

lain's avatar
lain committed
16
17
18
  # See http://elixir-lang.org/docs/stable/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
Thog's avatar
Thog committed
19
    import Cachex.Spec
lain's avatar
lain committed
20
21

    # Define workers and child supervisors to be supervised
lain's avatar
lain committed
22
23
24
25
    children =
      [
        # Start the Ecto repository
        supervisor(Pleroma.Repo, []),
href's avatar
href committed
26
        worker(Pleroma.Emoji, []),
27
        worker(Pleroma.Captcha, []),
28
29
        worker(
          Cachex,
lain's avatar
lain committed
30
          [
31
32
33
34
35
36
37
38
39
40
41
            :user_cache,
            [
              default_ttl: 25000,
              ttl_interval: 1000,
              limit: 2500
            ]
          ],
          id: :cachex_user
        ),
        worker(
          Cachex,
lain's avatar
lain committed
42
          [
43
44
45
46
47
48
49
50
51
            :object_cache,
            [
              default_ttl: 25000,
              ttl_interval: 1000,
              limit: 2500
            ]
          ],
          id: :cachex_object
        ),
52
53
54
55
56
        worker(
          Cachex,
          [
            :idempotency_cache,
            [
Thog's avatar
Thog committed
57
58
59
60
61
              expiration:
                expiration(
                  default: :timer.seconds(6 * 60 * 60),
                  interval: :timer.seconds(60)
                ),
62
63
64
65
66
              limit: 2500
            ]
          ],
          id: :cachex_idem
        ),
eal's avatar
eal committed
67
        worker(Pleroma.Web.Federator.RetryQueue, []),
href's avatar
href committed
68
        worker(Pleroma.Web.Federator, []),
minibikini's avatar
minibikini committed
69
70
        worker(Pleroma.Stats, []),
        worker(Pleroma.Web.Push, [])
lain's avatar
lain committed
71
      ] ++
href's avatar
href committed
72
73
74
75
76
77
78
        streamer_child() ++
        chat_child() ++
        [
          # Start the endpoint when the application starts
          supervisor(Pleroma.Web.Endpoint, []),
          worker(Pleroma.Gopher.Server, [])
        ]
lain's avatar
lain committed
79
80
81
82
83
84

    # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
    Supervisor.start_link(children, opts)
  end
85

href's avatar
href committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  if Mix.env() == :test do
    defp streamer_child(), do: []
    defp chat_child(), do: []
  else
    defp streamer_child() do
      [worker(Pleroma.Web.Streamer, [])]
    end

    defp chat_child() do
      if Pleroma.Config.get([:chat, :enabled]) do
        [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
      else
        []
      end
    end
101
  end
lain's avatar
lain committed
102
end