add license boilerplate to pleroma core
[akkoma] / lib / pleroma / application.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Application do
6 use Application
7 import Supervisor.Spec
8
9 @name "Pleroma"
10 @version Mix.Project.config()[:version]
11 def name, do: @name
12 def version, do: @version
13 def named_version(), do: @name <> " " <> @version
14
15 def user_agent() do
16 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
17 named_version() <> "; " <> info
18 end
19
20 # See http://elixir-lang.org/docs/stable/elixir/Application.html
21 # for more information on OTP Applications
22 def start(_type, _args) do
23 import Cachex.Spec
24
25 # Define workers and child supervisors to be supervised
26 children =
27 [
28 # Start the Ecto repository
29 supervisor(Pleroma.Repo, []),
30 worker(Pleroma.Emoji, []),
31 worker(Pleroma.Captcha, []),
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.RetryQueue, []),
72 worker(Pleroma.Web.Federator, []),
73 worker(Pleroma.Stats, []),
74 worker(Pleroma.Web.Push, [])
75 ] ++
76 streamer_child() ++
77 chat_child() ++
78 [
79 # Start the endpoint when the application starts
80 supervisor(Pleroma.Web.Endpoint, []),
81 worker(Pleroma.Gopher.Server, [])
82 ]
83
84 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
85 # for other strategies and supported options
86 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
87 Supervisor.start_link(children, opts)
88 end
89
90 if Mix.env() == :test do
91 defp streamer_child(), do: []
92 defp chat_child(), do: []
93 else
94 defp streamer_child() do
95 [worker(Pleroma.Web.Streamer, [])]
96 end
97
98 defp chat_child() do
99 if Pleroma.Config.get([:chat, :enabled]) do
100 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
101 else
102 []
103 end
104 end
105 end
106 end