Skip to content

Commit

Permalink
Configure sweeper interval in minutes
Browse files Browse the repository at this point in the history
* Restore `minute_to_ms` function
* Pipe interval option through `minute_to_ms`
  • Loading branch information
RichDom2185 committed Sep 17, 2023
1 parent 1003ca1 commit f27a470
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/guardian/db/sweeper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ defmodule Guardian.DB.Sweeper do

alias Guardian.DB.Token

@sixty_minutes 60 * 60 * 1000
@sixty_minutes 60

def start_link(opts) do
interval = Keyword.get(opts, :interval, @sixty_minutes)
interval = Keyword.get(opts, :interval, @sixty_minutes) |> minute_to_ms()
GenServer.start_link(__MODULE__, [interval: interval], name: __MODULE__)
end

Expand Down Expand Up @@ -67,4 +67,13 @@ defmodule Guardian.DB.Sweeper do

[interval: interval, timer: timer]
end

defp minute_to_ms(value) when is_binary(value) do
value
|> String.to_integer()
|> minute_to_ms()
end

defp minute_to_ms(value) when value < 1, do: 1000
defp minute_to_ms(value), do: round(value * 60 * 1000)
end

0 comments on commit f27a470

Please sign in to comment.