c65bebb3b98a0a3cffb462a87d3931340de7c9f2
[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 worker(Pleroma.Web.Federator.RetryQueue, []),
106 worker(Pleroma.Web.Federator, []),
107 worker(Pleroma.Stats, []),
108 worker(Pleroma.Web.Push, [])
109 ] ++
110 streamer_child() ++
111 chat_child() ++
112 [
113 # Start the endpoint when the application starts
114 supervisor(Pleroma.Web.Endpoint, []),
115 worker(Pleroma.Gopher.Server, [])
116 ]
117
118 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
119 # for other strategies and supported options
120 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
121 Supervisor.start_link(children, opts)
122 end
123
124 if Mix.env() == :test do
125 defp streamer_child(), do: []
126 defp chat_child(), do: []
127 else
128 defp streamer_child() do
129 [worker(Pleroma.Web.Streamer, [])]
130 end
131
132 defp chat_child() do
133 if Pleroma.Config.get([:chat, :enabled]) do
134 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
135 else
136 []
137 end
138 end
139 end
140 end