Obvs
Obvs copied to clipboard
Runtime configuration?
I want to use hammer via redis, but if I configure it as in the docs, I have to specify my redis host and password at compile time, which I absolutely don't want to do.
What I ended up having to do was, to prevent hammer from starting itself.
{:hammer, "~> 6.0.0", runtime: false},
{:hammer_plug, "~> 2.1", runtime: false},
{:hammer_backend_redis, "~> 6.1", runtime: false}
Add a dummy config so that when it picks a pool, it knows what its name will be.
config :hammer,
backend: {Hammer.Backend.Redis, nil}
Add it manually to my supervision tree at runtime with the config of my choice
defmodule MyApp.Hammer do
def child_spec do
%{
id: Hammer.Supervisor,
start:
{Hammer.Supervisor, :start_link,
[
{Hammer.Backend.Redis,
[
expiry_ms: 60_000,
redix_config: [
host: System.get_env("REDIS_HOST") || raise("env var REDIS_HOST required"),
password: System.get_env("REDIS_PASS") || raise("env var REDIS_PASS required")
]
]},
[name: Hammer.Supervisor]
]}
}
end
end
defmodule MyApp.Supervisor do
def init(_args) do
processes = [
...
MyApp.Hammer
] |> Supervisor.init(...)
end
end
Is there an easier way of doing what I just did?
This setup technically works but I ran into some problems with releases, so I went ahead and submitted a pr with the ability to specify runtime config instead. Hopefully that works better for people.
@mindreader what PR did you create?
I think the pr was accepted a long long time ago, but this was never closed.