Merge branch '534_federation_targets_reachability' into 'develop'
[akkoma] / lib / pleroma / application.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Application do
6 use Application
7 import Supervisor.Spec
8
9 @name "Pleroma"
10 @version Mix.Project.config()[:version]
11 def name, do: @name
12 def version, do: @version
13 def named_version(), do: @name <> " " <> @version
14
15 def user_agent() do
16 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
17 named_version() <> "; " <> info
18 end
19
20 # See http://elixir-lang.org/docs/stable/elixir/Application.html
21 # for more information on OTP Applications
22 def start(_type, _args) do
23 import Cachex.Spec
24
25 Pleroma.Config.DeprecationWarnings.warn()
26
27 # Define workers and child supervisors to be supervised
28 children =
29 [
30 # Start the Ecto repository
31 supervisor(Pleroma.Repo, []),
32 worker(Pleroma.Emoji, []),
33 worker(Pleroma.Captcha, []),
34 worker(
35 Cachex,
36 [
37 :used_captcha_cache,
38 [
39 ttl_interval: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
40 ]
41 ],
42 id: :cachex_used_captcha_cache
43 ),
44 worker(
45 Cachex,
46 [
47 :user_cache,
48 [
49 default_ttl: 25000,
50 ttl_interval: 1000,
51 limit: 2500
52 ]
53 ],
54 id: :cachex_user
55 ),
56 worker(
57 Cachex,
58 [
59 :object_cache,
60 [
61 default_ttl: 25000,
62 ttl_interval: 1000,
63 limit: 2500
64 ]
65 ],
66 id: :cachex_object
67 ),
68 worker(
69 Cachex,
70 [
71 :rich_media_cache,
72 [
73 default_ttl: :timer.minutes(120),
74 limit: 5000
75 ]
76 ],
77 id: :cachex_rich_media
78 ),
79 worker(
80 Cachex,
81 [
82 :scrubber_cache,
83 [
84 limit: 2500
85 ]
86 ],
87 id: :cachex_scrubber
88 ),
89 worker(
90 Cachex,
91 [
92 :idempotency_cache,
93 [
94 expiration:
95 expiration(
96 default: :timer.seconds(6 * 60 * 60),
97 interval: :timer.seconds(60)
98 ),
99 limit: 2500
100 ]
101 ],
102 id: :cachex_idem
103 ),
104 worker(Pleroma.FlakeId, [])
105 ] ++
106 hackney_pool_children() ++
107 [
108 worker(Pleroma.Web.Federator.RetryQueue, []),
109 worker(Pleroma.Web.Federator, []),
110 worker(Pleroma.Stats, []),
111 worker(Pleroma.Web.Push, [])
112 ] ++
113 streamer_child() ++
114 chat_child() ++
115 [
116 # Start the endpoint when the application starts
117 supervisor(Pleroma.Web.Endpoint, []),
118 worker(Pleroma.Gopher.Server, [])
119 ]
120
121 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
122 # for other strategies and supported options
123 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
124 Supervisor.start_link(children, opts)
125 end
126
127 def enabled_hackney_pools() do
128 [:media] ++
129 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
130 [:federation]
131 else
132 []
133 end ++
134 if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do
135 [:upload]
136 else
137 []
138 end
139 end
140
141 if Mix.env() == :test do
142 defp streamer_child(), do: []
143 defp chat_child(), do: []
144 else
145 defp streamer_child() do
146 [worker(Pleroma.Web.Streamer, [])]
147 end
148
149 defp chat_child() do
150 if Pleroma.Config.get([:chat, :enabled]) do
151 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
152 else
153 []
154 end
155 end
156 end
157
158 defp hackney_pool_children() do
159 for pool <- enabled_hackney_pools() do
160 options = Pleroma.Config.get([:hackney_pools, pool])
161 :hackney_pool.child_spec(pool, options)
162 end
163 end
164 end