Merge branch 'captcha' 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 def start(_type, _args) do
19 import Cachex.Spec
20
21 # Define workers and child supervisors to be supervised
22 children =
23 [
24 # Start the Ecto repository
25 supervisor(Pleroma.Repo, []),
26 worker(Pleroma.Emoji, []),
27 worker(Pleroma.Captcha, []),
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 worker(Pleroma.Web.Push, [])
71 ] ++
72 streamer_child() ++
73 chat_child() ++
74 [
75 # Start the endpoint when the application starts
76 supervisor(Pleroma.Web.Endpoint, []),
77 worker(Pleroma.Gopher.Server, [])
78 ]
79
80 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
81 # for other strategies and supported options
82 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
83 Supervisor.start_link(children, opts)
84 end
85
86 if Mix.env() == :test do
87 defp streamer_child(), do: []
88 defp chat_child(), do: []
89 else
90 defp streamer_child() do
91 [worker(Pleroma.Web.Streamer, [])]
92 end
93
94 defp chat_child() do
95 if Pleroma.Config.get([:chat, :enabled]) do
96 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
97 else
98 []
99 end
100 end
101 end
102 end