Integrate refresh of Last.fm data (both per artist and batch)
This commit is contained in:
@@ -22,4 +22,10 @@ defmodule MusicLibrary.Artists.Batch do
|
||||
Artists.refresh_wikipedia_data_async(artist_info)
|
||||
end)
|
||||
end
|
||||
|
||||
def refresh_lastfm_data do
|
||||
Batch.run_on_all(from(r in ArtistInfo), "artist_info", fn artist_info ->
|
||||
Artists.fetch_lastfm_data_async(artist_info.id)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do
|
||||
with {:ok, _artist_info} <- MusicLibrary.Artists.fetch_artist_info(artist_id),
|
||||
{:ok, _artist_info} <- MusicLibrary.Artists.fetch_wikipedia_data(artist_id),
|
||||
{:ok, _artist_info} <- MusicLibrary.Artists.fetch_image(artist_id) do
|
||||
# fetch_lastfm_data returns {:ok, _} even on API errors, so it won't block embeddings
|
||||
MusicLibrary.Artists.fetch_lastfm_data(artist_id)
|
||||
regenerate_record_embeddings(artist_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
defmodule MusicLibrary.Worker.FetchArtistLastFmData do
|
||||
use Oban.Worker, queue: :default, max_attempts: 3
|
||||
use Oban.Worker, queue: :last_fm, max_attempts: 3
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"id" => artist_id}}) do
|
||||
case MusicLibrary.Artists.fetch_lastfm_data(artist_id) do
|
||||
{:ok, _artist_info} -> :ok
|
||||
error -> error
|
||||
end
|
||||
result =
|
||||
case MusicLibrary.Artists.fetch_lastfm_data(artist_id) do
|
||||
{:ok, _artist_info} -> :ok
|
||||
error -> error
|
||||
end
|
||||
|
||||
Process.sleep(500)
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user