Merge branch 'classic-flakeids' 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 # Define workers and child supervisors to be supervised
26 children =
27 [
28 # Start the Ecto repository
29 supervisor(Pleroma.Repo, []),
30 worker(Pleroma.Emoji, []),
31 worker(Pleroma.Captcha, []),
32 worker(
33 Cachex,
34 [
35 :used_captcha_cache,
36 [
37 ttl_interval: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
38 ]
39 ],
40 id: :cachex_used_captcha_cache
41 ),
42 worker(
43 Cachex,
44 [
45 :user_cache,
46 [
47 default_ttl: 25000,
48 ttl_interval: 1000,
49 limit: 2500
50 ]
51 ],
52 id: :cachex_user
53 ),
54 worker(
55 Cachex,
56 [
57 :object_cache,
58 [
59 default_ttl: 25000,
60 ttl_interval: 1000,
61 limit: 2500
62 ]
63 ],
64 id: :cachex_object
65 ),
66 worker(
67 Cachex,
68 [
69 :rich_media_cache,
70 [
71 default_ttl: :timer.minutes(120),
72 limit: 5000
73 ]
74 ],
75 id: :cachex_rich_media
76 ),
77 worker(
78 Cachex,
79 [
80 :scrubber_cache,
81 [
82 limit: 2500
83 ]
84 ],
85 id: :cachex_scrubber
86 ),
87 worker(
88 Cachex,
89 [
90 :idempotency_cache,
91 [
92 expiration:
93 expiration(
94 default: :timer.seconds(6 * 60 * 60),
95 interval: :timer.seconds(60)
96 ),
97 limit: 2500
98 ]
99 ],
100 id: :cachex_idem
101 ),
102 worker(Pleroma.FlakeId, []),
103 worker(Pleroma.Web.Federator.RetryQueue, []),
104 worker(Pleroma.Web.Federator, []),
105 worker(Pleroma.Stats, []),
106 worker(Pleroma.Web.Push, [])
107 ] ++
108 streamer_child() ++
109 chat_child() ++
110 [
111 # Start the endpoint when the application starts
112 supervisor(Pleroma.Web.Endpoint, []),
113 worker(Pleroma.Gopher.Server, [])
114 ]
115
116 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
117 # for other strategies and supported options
118 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
119 Supervisor.start_link(children, opts)
120 end
121
122 if Mix.env() == :test do
123 defp streamer_child(), do: []
124 defp chat_child(), do: []
125 else
126 defp streamer_child() do
127 [worker(Pleroma.Web.Streamer, [])]
128 end
129
130 defp chat_child() do
131 if Pleroma.Config.get([:chat, :enabled]) do
132 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
133 else
134 []
135 end
136 end
137 end
138 end