Explicitly set auto-refresh config for LastFm refresh
This commit is contained in:
+1
-1
@@ -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
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user