From 2e57d978b6b19bb3824bf77ed20d6637e6706604 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 23 Jun 2024 22:44:48 +0200 Subject: [PATCH] Move Oban's remaining runtime config to Application module --- config/runtime.exs | 4 ---- lib/asciinema/application.ex | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index b5391de42..ce857abf6 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -145,10 +145,6 @@ if config_env() in [:prod, :dev] do config :asciinema, :unclaimed_recording_ttl, ttls end - if String.downcase("#{env.("CRON")}") in ["0", "false", "no"] do - config :asciinema, Oban, plugins: [{Oban.Plugins.Cron, crontab: []}] - end - if env.("SIGN_UP_DISABLED") in ["1", "true"] do config :asciinema, Asciinema.Accounts, sign_up_enabled?: false end diff --git a/lib/asciinema/application.ex b/lib/asciinema/application.ex index 0f4050a36..37a6004de 100644 --- a/lib/asciinema/application.ex +++ b/lib/asciinema/application.ex @@ -56,7 +56,22 @@ defmodule Asciinema.Application do defp cluster_topologies, do: Application.get_env(:libcluster, :topologies, []) - defp oban_config, do: Application.fetch_env!(:asciinema, Oban) + defp oban_config do + defaults = Application.fetch_env!(:asciinema, Oban) + + config = + if String.downcase("#{System.get_env("CRON")}") in ["0", "false"] do + deep_merge(defaults, plugins: [{Oban.Plugins.Cron, crontab: []}]) + else + defaults + end + + if System.get_env("INSPECT_CONFIG") do + IO.inspect(config, label: "oban config") + end + + config + end defp public_endpoint_config do defaults = take_app_env(AsciinemaWeb.Endpoint) @@ -151,6 +166,11 @@ defmodule Asciinema.Application do Keyword.merge(original, overrides, &on_conflict/3) end - defp on_conflict(_key, a, b) when is_list(a) and is_list(b), do: deep_merge(a, b) - defp on_conflict(_key, _a, b), do: b + defp on_conflict(_key, a, b) do + if Keyword.keyword?(a) and Keyword.keyword?(b) do + deep_merge(a, b) + else + b + end + end end