Correct ttl syntax for new cachex

This commit is contained in:
Floatingghost 2024-04-26 19:05:12 +01:00
parent 3c384c1b76
commit ec7e9da734
2 changed files with 4 additions and 7 deletions

View File

@ -49,7 +49,7 @@ defmodule Pleroma.HTTP.Backoff do
timestamp = next_backoff_timestamp(env)
ttl = Timex.diff(timestamp, DateTime.utc_now(), :seconds)
# we will cache the host for 5 minutes
@cachex.put(@backoff_cache, host, true, ttl)
@cachex.put(@backoff_cache, host, true, ttl: ttl)
{:error, :ratelimit}
_ ->

View File

@ -17,8 +17,7 @@ defmodule Pleroma.HTTP.BackoffTest do
test "should return {:error, env} when rate limited" do
# Shove a value into the cache to simulate a rate limit
Cachex.put(@backoff_cache, "akkoma.dev", true)
assert {:error, env} = Backoff.get("https://akkoma.dev/api/v1/instance")
assert env.status == 429
assert {:error, :ratelimit} = Backoff.get("https://akkoma.dev/api/v1/instance")
end
test "should insert a value into the cache when rate limited" do
@ -27,8 +26,7 @@ defmodule Pleroma.HTTP.BackoffTest do
{:ok, %Tesla.Env{status: 429, body: "Rate limited"}}
end)
assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert env.status == 429
assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev")
end
@ -46,8 +44,7 @@ defmodule Pleroma.HTTP.BackoffTest do
}}
end)
assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert env.status == 429
assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev")
end
end