application.ex 2.6 KB
Newer Older
lain's avatar
lain committed
1
2
3
defmodule Pleroma.Application do
  use Application

href's avatar
href committed
4
5
6
7
8
9
  @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
10
11
12
13
14
  def user_agent() do
    info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
    named_version() <> "; " <> info
  end

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

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

    # 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
91
92
93
94

  defp chat_enabled do
    Application.get_env(:pleroma, :chat, []) |> Keyword.get(:enabled)
  end
lain's avatar
lain committed
95
end