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