Merge branch 'feature/reverse-proxy' into 'develop'
[akkoma] / lib / pleroma / application.ex
1 defmodule Pleroma.Application do
2 use Application
3 import Supervisor.Spec
4
5 @name "Pleroma"
6 @version Mix.Project.config()[:version]
7 def name, do: @name
8 def version, do: @version
9 def named_version(), do: @name <> " " <> @version
10
11 def user_agent() do
12 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
13 named_version() <> "; " <> info
14 end
15
16 # See http://elixir-lang.org/docs/stable/elixir/Application.html
17 # for more information on OTP Applications
18 @env Mix.env()
19 def start(_type, _args) do
20 import Cachex.Spec
21
22 # Define workers and child supervisors to be supervised
23 children =
24 [
25 # Start the Ecto repository
26 supervisor(Pleroma.Repo, []),
27 worker(Pleroma.Emoji, []),
28 worker(
29 Cachex,
30 [
31 :user_cache,
32 [
33 default_ttl: 25000,
34 ttl_interval: 1000,
35 limit: 2500
36 ]
37 ],
38 id: :cachex_user
39 ),
40 worker(
41 Cachex,
42 [
43 :object_cache,
44 [
45 default_ttl: 25000,
46 ttl_interval: 1000,
47 limit: 2500
48 ]
49 ],
50 id: :cachex_object
51 ),
52 worker(
53 Cachex,
54 [
55 :idempotency_cache,
56 [
57 expiration:
58 expiration(
59 default: :timer.seconds(6 * 60 * 60),
60 interval: :timer.seconds(60)
61 ),
62 limit: 2500
63 ]
64 ],
65 id: :cachex_idem
66 ),
67 worker(Pleroma.Web.Federator.RetryQueue, []),
68 worker(Pleroma.Web.Federator, []),
69 worker(Pleroma.Stats, [])
70 ] ++
71 streamer_child() ++
72 chat_child() ++
73 [
74 # Start the endpoint when the application starts
75 supervisor(Pleroma.Web.Endpoint, []),
76 worker(Pleroma.Gopher.Server, [])
77 ]
78
79 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
80 # for other strategies and supported options
81 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
82 Supervisor.start_link(children, opts)
83 end
84
85 if Mix.env() == :test do
86 defp streamer_child(), do: []
87 defp chat_child(), do: []
88 else
89 defp streamer_child() do
90 [worker(Pleroma.Web.Streamer, [])]
91 end
92
93 defp chat_child() do
94 if Pleroma.Config.get([:chat, :enabled]) do
95 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
96 else
97 []
98 end
99 end
100 end
101 end