Skip to content

Commit

Permalink
fix: keep a consistent connection_opts throughout various environments
Browse files Browse the repository at this point in the history
  • Loading branch information
nlwstein committed Feb 9, 2024
1 parent 70db24d commit c5d888c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apps/api_web/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ config :api_web, ApiWeb.Endpoint,

config :api_web, :signing_salt, "NdisAeo6Jf02spiKqa"

config :api_web, RateLimiter.Memcache,
connection_opts: [
namespace: "api_dev_rate_limit",
hostname: "localhost",
coder: Memcache.Coder.JSON
]

config :api_web, :rate_limiter,
clear_interval: 60_000,
limiter: ApiWeb.RateLimiter.ETS,
Expand Down
3 changes: 2 additions & 1 deletion apps/api_web/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ config :api_web, :rate_limiter,
config :api_web, RateLimiter.Memcache,
connection_opts: [
namespace: "api_test_rate_limit",
hostname: "localhost"
hostname: "localhost",
coder: Memcache.Coder.JSON
]

config :api_web, ApiWeb.Plugs.ModifiedSinceHandler, check_caller: true
Expand Down
6 changes: 5 additions & 1 deletion apps/api_web/lib/api_web/rate_limiter/memcache/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ defmodule ApiWeb.RateLimiter.Memcache.Supervisor do
if memcache_required?() do
clear_interval_ms = Keyword.fetch!(@rate_limit_config, :clear_interval)
clear_interval = div(clear_interval_ms, 1000)
connection_opts_config = Keyword.fetch!(@rate_limit_config, :connection_opts)

connection_opts_config =
Application.fetch_env!(:api_web, RateLimiter.Memcache)
|> Keyword.fetch!(:connection_opts)

connection_opts = [ttl: clear_interval * 2] ++ connection_opts_config

workers =
Expand Down

0 comments on commit c5d888c

Please sign in to comment.