cb3e6b69b0c43f3e16ce5bf8ae60635cca21740a
[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 :scrubber_cache,
70 [
71 limit: 2500
72 ]
73 ],
74 id: :cachex_scrubber
75 ),
76 worker(
77 Cachex,
78 [
79 :idempotency_cache,
80 [
81 expiration:
82 expiration(
83 default: :timer.seconds(6 * 60 * 60),
84 interval: :timer.seconds(60)
85 ),
86 limit: 2500
87 ]
88 ],
89 id: :cachex_idem
90 ),
91 worker(Pleroma.Web.Federator.RetryQueue, []),
92 worker(Pleroma.Web.Federator, []),
93 worker(Pleroma.Stats, []),
94 worker(Pleroma.Web.Push, [])
95 ] ++
96 streamer_child() ++
97 chat_child() ++
98 [
99 # Start the endpoint when the application starts
100 supervisor(Pleroma.Web.Endpoint, []),
101 worker(Pleroma.Gopher.Server, [])
102 ]
103
104 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
105 # for other strategies and supported options
106 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
107 Supervisor.start_link(children, opts)
108 end
109
110 if Mix.env() == :test do
111 defp streamer_child(), do: []
112 defp chat_child(), do: []
113 else
114 defp streamer_child() do
115 [worker(Pleroma.Web.Streamer, [])]
116 end
117
118 defp chat_child() do
119 if Pleroma.Config.get([:chat, :enabled]) do
120 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
121 else
122 []
123 end
124 end
125 end
126 end