application.ex 4.19 KB
Newer Older
1
# Pleroma: A lightweight social networking server
kaniini's avatar
kaniini committed
2
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3
4
# SPDX-License-Identifier: AGPL-3.0-only

lain's avatar
lain committed
5
6
defmodule Pleroma.Application do
  use Application
href's avatar
href committed
7
  import Supervisor.Spec
lain's avatar
lain committed
8

9
  @name Mix.Project.config()[:name]
href's avatar
href committed
10
  @version Mix.Project.config()[:version]
11
  @repository Mix.Project.config()[:source_url]
href's avatar
href committed
12
13
  def name, do: @name
  def version, do: @version
14
  def named_version, do: @name <> " " <> @version
luna's avatar
luna committed
15
  def repository, do: @repository
href's avatar
href committed
16

17
  def user_agent do
href's avatar
href committed
18
19
20
21
    info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
    named_version() <> "; " <> info
  end

lain's avatar
lain committed
22
23
24
  # 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
25
    import Cachex.Spec
lain's avatar
lain committed
26

27
    Pleroma.Config.DeprecationWarnings.warn()
lain's avatar
lain committed
28

lain's avatar
lain committed
29
    # Define workers and child supervisors to be supervised
lain's avatar
lain committed
30
31
32
33
    children =
      [
        # Start the Ecto repository
        supervisor(Pleroma.Repo, []),
href's avatar
href committed
34
        worker(Pleroma.Emoji, []),
35
        worker(Pleroma.Captcha, []),
36
37
38
39
40
        worker(
          Cachex,
          [
            :used_captcha_cache,
            [
41
              ttl_interval: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
42
43
44
45
            ]
          ],
          id: :cachex_used_captcha_cache
        ),
46
47
        worker(
          Cachex,
lain's avatar
lain committed
48
          [
49
50
            :user_cache,
            [
51
              default_ttl: 25_000,
52
53
54
55
56
57
58
59
              ttl_interval: 1000,
              limit: 2500
            ]
          ],
          id: :cachex_user
        ),
        worker(
          Cachex,
lain's avatar
lain committed
60
          [
61
62
            :object_cache,
            [
63
              default_ttl: 25_000,
64
65
66
67
68
69
              ttl_interval: 1000,
              limit: 2500
            ]
          ],
          id: :cachex_object
        ),
70
71
72
73
74
75
76
77
78
79
80
        worker(
          Cachex,
          [
            :rich_media_cache,
            [
              default_ttl: :timer.minutes(120),
              limit: 5000
            ]
          ],
          id: :cachex_rich_media
        ),
81
82
83
84
85
86
87
88
89
90
        worker(
          Cachex,
          [
            :scrubber_cache,
            [
              limit: 2500
            ]
          ],
          id: :cachex_scrubber
        ),
91
92
93
94
95
        worker(
          Cachex,
          [
            :idempotency_cache,
            [
Thog's avatar
Thog committed
96
97
98
99
100
              expiration:
                expiration(
                  default: :timer.seconds(6 * 60 * 60),
                  interval: :timer.seconds(60)
                ),
101
102
103
104
105
              limit: 2500
            ]
          ],
          id: :cachex_idem
        ),
href's avatar
href committed
106
        worker(Pleroma.FlakeId, [])
lain's avatar
lain committed
107
      ] ++
href's avatar
href committed
108
109
110
111
        hackney_pool_children() ++
        [
          worker(Pleroma.Web.Federator.RetryQueue, []),
          worker(Pleroma.Stats, []),
112
113
          worker(Pleroma.Web.Push, []),
          worker(Pleroma.Jobs, []),
minibikini's avatar
minibikini committed
114
          worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary)
href's avatar
href committed
115
        ] ++
href's avatar
href committed
116
117
118
119
120
121
122
        streamer_child() ++
        chat_child() ++
        [
          # Start the endpoint when the application starts
          supervisor(Pleroma.Web.Endpoint, []),
          worker(Pleroma.Gopher.Server, [])
        ]
lain's avatar
lain committed
123
124
125
126
127
128

    # 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
129

130
  def enabled_hackney_pools do
href's avatar
href committed
131
132
133
134
135
136
137
    [:media] ++
      if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
        [:federation]
      else
        []
      end ++
      if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do
href's avatar
href committed
138
        [:upload]
href's avatar
href committed
139
140
141
142
143
      else
        []
      end
  end

href's avatar
href committed
144
  if Mix.env() == :test do
145
146
    defp streamer_child, do: []
    defp chat_child, do: []
href's avatar
href committed
147
  else
148
    defp streamer_child do
href's avatar
href committed
149
150
151
      [worker(Pleroma.Web.Streamer, [])]
    end

152
    defp chat_child do
href's avatar
href committed
153
154
155
156
157
158
      if Pleroma.Config.get([:chat, :enabled]) do
        [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
      else
        []
      end
    end
159
  end
href's avatar
href committed
160

161
  defp hackney_pool_children do
href's avatar
href committed
162
163
164
165
166
    for pool <- enabled_hackney_pools() do
      options = Pleroma.Config.get([:hackney_pools, pool])
      :hackney_pool.child_spec(pool, options)
    end
  end
lain's avatar
lain committed
167
end