Skip to content

Commit

Permalink
Move Oban's remaining runtime config to Application module
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jul 1, 2024
1 parent 14d2f92 commit 2e57d97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 0 additions & 4 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions lib/asciinema/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 2e57d97

Please sign in to comment.