Merge remote-tracking branch 'official/develop' into develop
[akkoma] / lib / pleroma / application.ex
1 defmodule Pleroma.Application do
2 use Application
3
4 # See http://elixir-lang.org/docs/stable/elixir/Application.html
5 # for more information on OTP Applications
6 def start(_type, _args) do
7 import Supervisor.Spec
8 import Cachex.Spec
9
10 # Define workers and child supervisors to be supervised
11 children =
12 [
13 # Start the Ecto repository
14 supervisor(Pleroma.Repo, []),
15 worker(Pleroma.Emoji, []),
16 # Start the endpoint when the application starts
17 supervisor(Pleroma.Web.Endpoint, []),
18 # Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3)
19 # worker(Pleroma.Worker, [arg1, arg2, arg3]),
20 worker(
21 Cachex,
22 [
23 :user_cache,
24 [
25 default_ttl: 25000,
26 ttl_interval: 1000,
27 limit: 2500
28 ]
29 ],
30 id: :cachex_user
31 ),
32 worker(
33 Cachex,
34 [
35 :object_cache,
36 [
37 default_ttl: 25000,
38 ttl_interval: 1000,
39 limit: 2500
40 ]
41 ],
42 id: :cachex_object
43 ),
44 worker(
45 Cachex,
46 [
47 :idempotency_cache,
48 [
49 expiration:
50 expiration(
51 default: :timer.seconds(6 * 60 * 60),
52 interval: :timer.seconds(60)
53 ),
54 limit: 2500
55 ]
56 ],
57 id: :cachex_idem
58 ),
59 worker(Pleroma.Web.Federator, []),
60 worker(Pleroma.Stats, []),
61 worker(Pleroma.Gopher.Server, [])
62 ] ++
63 if Mix.env() == :test,
64 do: [],
65 else:
66 [worker(Pleroma.Web.Streamer, [])] ++
67 if(
68 !chat_enabled(),
69 do: [],
70 else: [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
71 )
72
73 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
74 # for other strategies and supported options
75 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
76 Supervisor.start_link(children, opts)
77 end
78
79 defp chat_enabled do
80 Application.get_env(:pleroma, :chat, []) |> Keyword.get(:enabled)
81 end
82 end