1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Application do
8 @name Mix.Project.config()[:name]
9 @version Mix.Project.config()[:version]
10 @repository Mix.Project.config()[:source_url]
12 def version, do: @version
13 def named_version, do: @name <> " " <> @version
14 def repository, do: @repository
17 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
18 named_version() <> "; " <> info
21 # See http://elixir-lang.org/docs/stable/elixir/Application.html
22 # for more information on OTP Applications
23 def start(_type, _args) do
26 Pleroma.Config.DeprecationWarnings.warn()
29 # Define workers and child supervisors to be supervised
32 # Start the Ecto repository
33 %{id: Pleroma.Repo, start: {Pleroma.Repo, :start_link, []}, type: :supervisor},
34 %{id: Pleroma.Config.TransferTask, start: {Pleroma.Config.TransferTask, :start_link, []}},
35 %{id: Pleroma.Emoji, start: {Pleroma.Emoji, :start_link, []}},
36 %{id: Pleroma.Captcha, start: {Pleroma.Captcha, :start_link, []}},
38 id: :cachex_used_captcha_cache,
45 :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
76 id: :cachex_rich_media,
82 default_ttl: :timer.minutes(120),
101 {Cachex, :start_link,
107 default: :timer.seconds(6 * 60 * 60),
108 interval: :timer.seconds(60)
114 %{id: Pleroma.FlakeId, start: {Pleroma.FlakeId, :start_link, []}},
116 id: Pleroma.ScheduledActivityWorker,
117 start: {Pleroma.ScheduledActivityWorker, :start_link, []}
120 id: Pleroma.QuantumScheduler,
121 start: {Pleroma.QuantumScheduler, :start_link, []}
124 hackney_pool_children() ++
127 id: Pleroma.Web.Federator.RetryQueue,
128 start: {Pleroma.Web.Federator.RetryQueue, :start_link, []}
131 id: Pleroma.Web.OAuth.Token.CleanWorker,
132 start: {Pleroma.Web.OAuth.Token.CleanWorker, :start_link, []}
136 start: {Pleroma.Stats, :start_link, []}
140 start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
145 start: {Task, :start_link, [&Pleroma.Web.Federator.init/0]},
152 # Start the endpoint when the application starts
154 id: Pleroma.Web.Endpoint,
155 start: {Pleroma.Web.Endpoint, :start_link, []},
158 %{id: Pleroma.Gopher.Server, start: {Pleroma.Gopher.Server, :start_link, []}}
161 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
162 # for other strategies and supported options
163 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
164 result = Supervisor.start_link(children, opts)
165 :ok = after_supervisor_start()
169 defp setup_instrumenters do
170 require Prometheus.Registry
172 if Application.get_env(:prometheus, Pleroma.Repo.Instrumenter) do
176 [:pleroma, :repo, :query],
177 &Pleroma.Repo.Instrumenter.handle_event/4,
181 Pleroma.Repo.Instrumenter.setup()
184 Pleroma.Web.Endpoint.MetricsExporter.setup()
185 Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
186 Pleroma.Web.Endpoint.Instrumenter.setup()
189 def enabled_hackney_pools do
191 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
196 if Pleroma.Config.get([Pleroma.Upload, :proxy_remote]) do
203 if Pleroma.Config.get(:env) == :test do
204 defp streamer_child, do: []
205 defp chat_child, do: []
207 defp streamer_child do
208 [%{id: Pleroma.Web.Streamer, start: {Pleroma.Web.Streamer, :start_link, []}}]
212 if Pleroma.Config.get([:chat, :enabled]) do
215 id: Pleroma.Web.ChatChannel.ChatChannelState,
216 start: {Pleroma.Web.ChatChannel.ChatChannelState, :start_link, []}
225 defp hackney_pool_children do
226 for pool <- enabled_hackney_pools() do
227 options = Pleroma.Config.get([:hackney_pools, pool])
228 :hackney_pool.child_spec(pool, options)
232 defp after_supervisor_start do
233 with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
234 true <- digest_config[:active],
235 %Crontab.CronExpression{} = schedule <-
236 Crontab.CronExpression.Parser.parse!(digest_config[:schedule]) do
237 Pleroma.QuantumScheduler.new_job()
238 |> Quantum.Job.set_name(:digest_emails)
239 |> Quantum.Job.set_schedule(schedule)
240 |> Quantum.Job.set_task(&Pleroma.DigestEmailWorker.run/0)
241 |> Pleroma.QuantumScheduler.add_job()