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