I’m trying to use ExRated to rate limit mail. I’m struggling with two things because I don’t have a strong knowledge of OTP.
The installation instructions say to add these into mix.exs
[{:ex_rated, "~> 2.0"}]
end
[applications: [:ex_rated]]
end
Yep, yep … I know to add :ex_rated to “extra_applications:” since I’m on a newer version of elixir.
But here is where I get confused …
There are no instructions to add ExRated to my “children” list in the start() function of application.ex. If ExRated stores state using an OTP server, then doesn’t it need to be started and supervised?
The instructions say that I can also start it manually by calling:
{:ok, pid} = GenServer.start_link(ExRated, [ {:timeout, 10_000}, {:cleanup_rate, 10_000}, {:persistent, false} ], [name: :ex_rated])
I would prefer it to start automatically with my app. If I want it to start automatically, then don’t I need to add the module to my start children[] list in application.ex?
The other thing that is confusing for me is that he says to run:
mix test —no-start
when I do tests. I understand why, but the execution is going to get tricky.
I can’t change my mix alias for test to be “test --no-start” because I need some of my other servers to run. I was going to follow advice by @mbklein and use environment variables to only run ExRated’s OTP server if i’m not in :test mode. But I can’t set up that condition in the applixation.ex start function … if ExRated isn’t listed there.
I must be missing something. Any advice would be most appreciated.