Explicitly set auto-refresh config for LastFm refresh

This commit is contained in:
Claudio Ortolina
2024-12-03 19:58:17 +00:00
parent f58a5e83b7
commit 61cda5a62c
4 changed files with 5 additions and 8 deletions
+1 -1
View File
@@ -25,9 +25,9 @@ config :music_library, MusicLibraryWeb.Endpoint,
live_view: [signing_salt: "g/qw4SNo"]
config :music_library, LastFm,
# to avoid runtime errors, set the user to a valid Last.fm username
user: "username",
api: LastFm.APIImpl,
auto_refresh: true,
refresh_interval: System.convert_time_unit(60, :second, :millisecond),
api_key: "change me"
+1 -1
View File
@@ -30,4 +30,4 @@ config :phoenix_live_view,
config :music_library, dev_routes: true
config :music_library, LastFm, api: nil
config :music_library, LastFm, auto_refresh: false
+2 -5
View File
@@ -3,19 +3,16 @@ defmodule LastFm.Config do
api: module(),
api_key: String.t(),
user: String.t(),
auto_refresh: boolean(),
refresh_interval: pos_integer()
}
defstruct api: LastFm.Api,
api_key: "",
user: "",
auto_refresh: true,
refresh_interval: 60_000
@spec enabled?(t) :: boolean()
def enabled?(config) do
config.api && config.user !== "" && config.api_key !== ""
end
@spec resolve(atom) :: t
def resolve(otp_app) do
app_config =
+1 -1
View File
@@ -20,7 +20,7 @@ defmodule LastFm.Refresh do
@impl true
@spec init(config) :: {:ok, config, {:continue, :refresh}} | :ignore
def init(config) do
if Config.enabled?(config) do
if config.auto_refresh do
{:ok, config, {:continue, :refresh}}
else
:ignore