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