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
9 @name Mix.Project.config()[:name]
10 @version Mix.Project.config()[:version]
11 @repository Mix.Project.config()[:source_url]
15 def version, do: @version
16 def named_version, do: @name <> " " <> @version
17 def repository, do: @repository
20 info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
21 named_version() <> "; " <> info
24 # See http://elixir-lang.org/docs/stable/elixir/Application.html
25 # for more information on OTP Applications
26 def start(_type, _args) do
27 Pleroma.Config.DeprecationWarnings.warn()
30 # Define workers and child supervisors to be supervised
34 Pleroma.Config.TransferTask,
38 Pleroma.ScheduledActivityWorker
41 hackney_pool_children() ++
46 start: {Oban, :start_link, [Application.get_env(:pleroma, Oban)]}
50 start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
55 start: {Task, :start_link, [&Pleroma.Web.Federator.init/0]},
59 id: :internal_fetch_init,
60 start: {Task, :start_link, [&Pleroma.Web.ActivityPub.InternalFetchActor.init/0]},
64 oauth_cleanup_child(oauth_cleanup_enabled?()) ++
65 streamer_child(@env) ++
66 chat_child(@env, chat_enabled?()) ++
72 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
73 # for other strategies and supported options
74 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
75 result = Supervisor.start_link(children, opts)
76 :ok = after_supervisor_start()
80 defp setup_instrumenters do
81 require Prometheus.Registry
83 if Application.get_env(:prometheus, Pleroma.Repo.Instrumenter) do
87 [:pleroma, :repo, :query],
88 &Pleroma.Repo.Instrumenter.handle_event/4,
92 Pleroma.Repo.Instrumenter.setup()
95 Pleroma.Web.Endpoint.MetricsExporter.setup()
96 Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
97 Pleroma.Web.Endpoint.Instrumenter.setup()
100 def enabled_hackney_pools do
102 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
107 if Pleroma.Config.get([Pleroma.Upload, :proxy_remote]) do
114 defp cachex_children do
116 build_cachex("used_captcha", ttl_interval: seconds_valid_interval()),
117 build_cachex("user", default_ttl: 25_000, ttl_interval: 1000, limit: 2500),
118 build_cachex("object", default_ttl: 25_000, ttl_interval: 1000, limit: 2500),
119 build_cachex("rich_media", default_ttl: :timer.minutes(120), limit: 5000),
120 build_cachex("scrubber", limit: 2500),
121 build_cachex("idempotency", expiration: idempotency_expiration(), limit: 2500)
125 defp idempotency_expiration,
126 do: expiration(default: :timer.seconds(6 * 60 * 60), interval: :timer.seconds(60))
128 defp seconds_valid_interval,
129 do: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
131 defp build_cachex(type, opts),
133 id: String.to_atom("cachex_" <> type),
134 start: {Cachex, :start_link, [String.to_atom(type <> "_cache"), opts]},
138 defp chat_enabled?, do: Pleroma.Config.get([:chat, :enabled])
140 defp oauth_cleanup_enabled?,
141 do: Pleroma.Config.get([:oauth2, :clean_expired_tokens], false)
143 defp streamer_child(:test), do: []
145 defp streamer_child(_) do
146 [Pleroma.Web.Streamer]
149 defp oauth_cleanup_child(true),
150 do: [Pleroma.Web.OAuth.Token.CleanWorker]
152 defp oauth_cleanup_child(_), do: []
154 defp chat_child(:test, _), do: []
156 defp chat_child(_env, true) do
157 [Pleroma.Web.ChatChannel.ChatChannelState]
160 defp chat_child(_, _), do: []
162 defp hackney_pool_children do
163 for pool <- enabled_hackney_pools() do
164 options = Pleroma.Config.get([:hackney_pools, pool])
165 :hackney_pool.child_spec(pool, options)
169 defp after_supervisor_start do
170 with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
171 true <- digest_config[:active] do
172 # TODO: consider replacing with `quantum` scheduler
173 PleromaJobQueue.schedule(
174 digest_config[:schedule],
176 Pleroma.DigestEmailWorker