Use PleromaJobQueue in Pleroma.Web.Push
[akkoma] / lib / pleroma / application.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 Mix.Project.config()[:name]
10 @version Mix.Project.config()[:version]
11 @repository Mix.Project.config()[:source_url]
12 def name, do: @name
13 def version, do: @version
14 def named_version, do: @name <> " " <> @version
15 def repository, do: @repository
16
17 def user_agent do
18 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
19 named_version() <> "; " <> info
20 end
21
22 # See http://elixir-lang.org/docs/stable/elixir/Application.html
23 # for more information on OTP Applications
24 def start(_type, _args) do
25 import Cachex.Spec
26
27 Pleroma.Config.DeprecationWarnings.warn()
28
29 # Define workers and child supervisors to be supervised
30 children =
31 [
32 # Start the Ecto repository
33 supervisor(Pleroma.Repo, []),
34 worker(Pleroma.Emoji, []),
35 worker(Pleroma.Captcha, []),
36 worker(
37 Cachex,
38 [
39 :used_captcha_cache,
40 [
41 ttl_interval: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
42 ]
43 ],
44 id: :cachex_used_captcha_cache
45 ),
46 worker(
47 Cachex,
48 [
49 :user_cache,
50 [
51 default_ttl: 25_000,
52 ttl_interval: 1000,
53 limit: 2500
54 ]
55 ],
56 id: :cachex_user
57 ),
58 worker(
59 Cachex,
60 [
61 :object_cache,
62 [
63 default_ttl: 25_000,
64 ttl_interval: 1000,
65 limit: 2500
66 ]
67 ],
68 id: :cachex_object
69 ),
70 worker(
71 Cachex,
72 [
73 :rich_media_cache,
74 [
75 default_ttl: :timer.minutes(120),
76 limit: 5000
77 ]
78 ],
79 id: :cachex_rich_media
80 ),
81 worker(
82 Cachex,
83 [
84 :scrubber_cache,
85 [
86 limit: 2500
87 ]
88 ],
89 id: :cachex_scrubber
90 ),
91 worker(
92 Cachex,
93 [
94 :idempotency_cache,
95 [
96 expiration:
97 expiration(
98 default: :timer.seconds(6 * 60 * 60),
99 interval: :timer.seconds(60)
100 ),
101 limit: 2500
102 ]
103 ],
104 id: :cachex_idem
105 ),
106 worker(Pleroma.FlakeId, [])
107 ] ++
108 hackney_pool_children() ++
109 [
110 worker(Pleroma.Web.Federator.RetryQueue, []),
111 worker(Pleroma.Stats, []),
112 worker(Task, [&Pleroma.Web.Push.init/0], restart: :temporary, id: :web_push_init),
113 worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary, id: :federator_init)
114 ] ++
115 streamer_child() ++
116 chat_child() ++
117 [
118 # Start the endpoint when the application starts
119 supervisor(Pleroma.Web.Endpoint, []),
120 worker(Pleroma.Gopher.Server, [])
121 ]
122
123 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
124 # for other strategies and supported options
125 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
126 Supervisor.start_link(children, opts)
127 end
128
129 def enabled_hackney_pools do
130 [:media] ++
131 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
132 [:federation]
133 else
134 []
135 end ++
136 if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do
137 [:upload]
138 else
139 []
140 end
141 end
142
143 if Mix.env() == :test do
144 defp streamer_child, do: []
145 defp chat_child, do: []
146 else
147 defp streamer_child do
148 [worker(Pleroma.Web.Streamer, [])]
149 end
150
151 defp chat_child do
152 if Pleroma.Config.get([:chat, :enabled]) do
153 [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
154 else
155 []
156 end
157 end
158 end
159
160 defp hackney_pool_children do
161 for pool <- enabled_hackney_pools() do
162 options = Pleroma.Config.get([:hackney_pools, pool])
163 :hackney_pool.child_spec(pool, options)
164 end
165 end
166 end