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