X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fapplication.ex;h=6bda2e1d97f7396085c7b20d89aa10a99633d52a;hb=0f132b802dde7f217ecb07767e0d34e3edb517b7;hp=b709e737bf2345dd1b032967274230cda8caeb22;hpb=7989b84d010d74123ee78f68fda4bc21746d4f87;p=akkoma diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index b709e737b..6bda2e1d9 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -47,7 +47,6 @@ defmodule Pleroma.Application do # Disable warnings_as_errors at runtime, it breaks Phoenix live reload # due to protocol consolidation warnings Code.compiler_options(warnings_as_errors: false) - Pleroma.Telemetry.Logger.attach() Config.Holder.save_default() Pleroma.HTML.compile_scrubbers() Pleroma.Config.Oban.warn() @@ -59,35 +58,6 @@ defmodule Pleroma.Application do Pleroma.Docs.JSON.compile() limiters_setup() - adapter = Application.get_env(:tesla, :adapter) - - if match?({Tesla.Adapter.Finch, _}, adapter) do - Logger.info("Starting Finch") - Finch.start_link(name: MyFinch) - end - - if adapter == Tesla.Adapter.Gun do - if version = Pleroma.OTPVersion.version() do - [major, minor] = - version - |> String.split(".") - |> Enum.map(&String.to_integer/1) - |> Enum.take(2) - - if (major == 22 and minor < 2) or major < 22 do - raise " - !!!OTP VERSION WARNING!!! - You are using gun adapter with OTP version #{version}, which doesn't support correct handling of unordered certificates chains. Please update your Erlang/OTP to at least 22.2. - " - end - else - raise " - !!!OTP VERSION WARNING!!! - To support correct handling of unordered certificates chains - OTP version must be > 22.2. - " - end - end - # Define workers and child supervisors to be supervised children = [ @@ -97,7 +67,7 @@ defmodule Pleroma.Application do Pleroma.Web.Plugs.RateLimiter.Supervisor ] ++ cachex_children() ++ - http_children(adapter, @mix_env) ++ + http_children() ++ [ Pleroma.Stats, Pleroma.JobQueueMonitor, @@ -107,17 +77,31 @@ defmodule Pleroma.Application do ] ++ elasticsearch_children() ++ task_children(@mix_env) ++ - dont_run_in_test(@mix_env) ++ - shout_child(shout_enabled?()) + dont_run_in_test(@mix_env) # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html # for other strategies and supported options - opts = [strategy: :one_for_one, name: Pleroma.Supervisor] - result = Supervisor.start_link(children, opts) + # If we have a lot of caches, default max_restarts can cause test + # resets to fail. + # Go for the default 3 unless we're in test + max_restarts = + if @mix_env == :test do + 100 + else + 3 + end - set_postgres_server_version() + opts = [strategy: :one_for_one, name: Pleroma.Supervisor, max_restarts: max_restarts] - result + with {:ok, data} <- Supervisor.start_link(children, opts) do + set_postgres_server_version() + {:ok, data} + else + e -> + Logger.error("Failed to start!") + Logger.error("#{inspect(e)}") + e + end end defp set_postgres_server_version do @@ -193,11 +177,7 @@ defmodule Pleroma.Application do build_cachex("web_resp", limit: 2500), build_cachex("emoji_packs", expiration: emoji_packs_expiration(), limit: 10), build_cachex("failed_proxy_url", limit: 2500), - build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000), - build_cachex("chat_message_id_idempotency_key", - expiration: chat_message_id_idempotency_key_expiration(), - limit: 500_000 - ) + build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000) ] end @@ -207,9 +187,6 @@ defmodule Pleroma.Application do defp idempotency_expiration, do: expiration(default: :timer.seconds(6 * 60 * 60), interval: :timer.seconds(60)) - defp chat_message_id_idempotency_key_expiration, - do: expiration(default: :timer.minutes(2), interval: :timer.seconds(60)) - defp seconds_valid_interval, do: :timer.seconds(Config.get!([Pleroma.Captcha, :seconds_valid])) @@ -221,8 +198,6 @@ defmodule Pleroma.Application do type: :worker } - defp shout_enabled?, do: Config.get([:shout, :enabled]) - defp dont_run_in_test(env) when env in [:test, :benchmark], do: [] defp dont_run_in_test(_) do @@ -242,15 +217,6 @@ defmodule Pleroma.Application do ] end - defp shout_child(true) do - [ - Pleroma.Web.ShoutChannel.ShoutChannelState, - {Phoenix.PubSub, [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2]} - ] - end - - defp shout_child(_), do: [] - defp task_children(:test) do [ %{ @@ -276,34 +242,6 @@ defmodule Pleroma.Application do ] end - # start hackney and gun pools in tests - defp http_children(_, :test) do - http_children(Tesla.Adapter.Hackney, nil) ++ http_children(Tesla.Adapter.Gun, nil) - end - - defp http_children(Tesla.Adapter.Hackney, _) do - pools = [:federation, :media] - - pools = - if Config.get([Pleroma.Upload, :proxy_remote]) do - [:upload | pools] - else - pools - end - - for pool <- pools do - options = Config.get([:hackney_pools, pool]) - :hackney_pool.child_spec(pool, options) - end - end - - defp http_children(Tesla.Adapter.Gun, _) do - Pleroma.Gun.ConnectionPool.children() ++ - [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}] - end - - defp http_children(_, _), do: [] - def elasticsearch_children do config = Config.get([Pleroma.Search, :module]) @@ -332,4 +270,13 @@ defmodule Pleroma.Application do ConcurrentLimiter.new(module, max_running, max_waiting) end) end + + defp http_children do + config = + [:http, :adapter] + |> Config.get([]) + |> Keyword.put(:name, MyFinch) + + [{Finch, config}] + end end