Merge branch 'docs/admin-api' 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 :user_cache,
36 [
37 default_ttl: 25000,
38 ttl_interval: 1000,
39 limit: 2500
40 ]
41 ],
42 id: :cachex_user
43 ),
44 worker(
45 Cachex,
46 [
47 :object_cache,
48 [
49 default_ttl: 25000,
50 ttl_interval: 1000,
51 limit: 2500
52 ]
53 ],
54 id: :cachex_object
55 ),
56 worker(
57 Cachex,
58 [
59 :scrubber_cache,
60 [
61 limit: 2500
62 ]
63 ],
64 id: :cachex_scrubber
65 ),
66 worker(
67 Cachex,
68 [
69 :idempotency_cache,
70 [
71 expiration:
72 expiration(
73 default: :timer.seconds(6 * 60 * 60),
74 interval: :timer.seconds(60)
75 ),
76 limit: 2500
77 ]
78 ],
79 id: :cachex_idem
80 ),
81 worker(Pleroma.Web.Federator.RetryQueue, []),
82 worker(Pleroma.Web.Federator, []),
83 worker(Pleroma.Stats, []),
84 worker(Pleroma.Web.Push, [])
85 ] ++
86 streamer_child() ++
87 chat_child() ++
88 [
89 # Start the endpoint when the application starts
90 supervisor(Pleroma.Web.Endpoint, []),
91 worker(Pleroma.Gopher.Server, [])
92 ]
93
94 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
95 # for other strategies and supported options
96 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
97 Supervisor.start_link(children, opts)
98 end
99
100 if Mix.env() == :test do
101 defp streamer_child(), do: []
102 defp chat_child(), do: []
103 else
104 defp streamer_child() do
105 [worker(Pleroma.Web.Streamer, [])]
106 end
107
108 defp chat_child() do
109 if Pleroma.Config.get([:chat, :enabled]) do
110 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
111 else
112 []
113 end
114 end
115 end
116 end