Don't suppress errors when fetching artist Last.fm data

Closes #149
This commit is contained in:
Claudio Ortolina
2026-04-05 15:47:36 +01:00
parent 501ff18733
commit a5df68c7ad
3 changed files with 10 additions and 17 deletions
+5 -9
View File
@@ -260,16 +260,12 @@ defmodule MusicLibrary.Artists do
artist_info = get_artist_info!(artist_id) artist_info = get_artist_info!(artist_id)
name = get_in(artist_info.musicbrainz_data, ["name"]) || "" name = get_in(artist_info.musicbrainz_data, ["name"]) || ""
case LastFm.get_artist_tags(artist_id, name) do with {:ok, tags} <- LastFm.get_artist_tags(artist_id, name) do
{:ok, tags} -> tag_names = Enum.map(tags, fn {tag_name, _count} -> tag_name end)
tag_names = Enum.map(tags, fn {tag_name, _count} -> tag_name end)
artist_info artist_info
|> ArtistInfo.changeset(%{lastfm_data: %{"tags" => tag_names}}) |> ArtistInfo.changeset(%{lastfm_data: %{"tags" => tag_names}})
|> Repo.update() |> Repo.update()
{:error, _reason} ->
{:ok, artist_info}
end end
end end
@@ -5,9 +5,8 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do
def perform(%Oban.Job{args: %{"id" => artist_id}}) do def perform(%Oban.Job{args: %{"id" => artist_id}}) do
with {:ok, _artist_info} <- MusicLibrary.Artists.refresh_artist_info(artist_id), with {:ok, _artist_info} <- MusicLibrary.Artists.refresh_artist_info(artist_id),
{:ok, _artist_info} <- MusicLibrary.Artists.refresh_wikipedia_data(artist_id), {:ok, _artist_info} <- MusicLibrary.Artists.refresh_wikipedia_data(artist_id),
{:ok, _artist_info} <- MusicLibrary.Artists.refresh_image(artist_id) do {:ok, _artist_info} <- MusicLibrary.Artists.refresh_image(artist_id),
# refresh_lastfm_data returns {:ok, _} even on API errors, so it won't block embeddings {:ok, _artist_info} <- MusicLibrary.Artists.refresh_lastfm_data(artist_id) do
MusicLibrary.Artists.refresh_lastfm_data(artist_id)
MusicLibrary.Records.regenerate_artist_embeddings(artist_id) MusicLibrary.Records.regenerate_artist_embeddings(artist_id)
else else
{:error, :no_english_wikipedia} -> {:cancel, :no_english_wikipedia} {:error, :no_english_wikipedia} -> {:cancel, :no_english_wikipedia}
@@ -39,15 +39,13 @@ defmodule MusicLibrary.Worker.FetchArtistLastFmDataTest do
end end
@tag :capture_log @tag :capture_log
test "returns ok when Last.fm returns an error", %{artist_id: artist_id} do test "returns error when Last.fm returns an error", %{artist_id: artist_id} do
Req.Test.stub(LastFm.API, fn conn -> Req.Test.stub(LastFm.API, fn conn ->
Req.Test.json(conn, %{"error" => 6, "message" => "Artist not found"}) Req.Test.json(conn, %{"error" => 6, "message" => "Artist not found"})
end) end)
assert :ok = perform_job(FetchArtistLastFmData, %{"id" => artist_id}) assert {:error, :invalid_parameters} ==
perform_job(FetchArtistLastFmData, %{"id" => artist_id})
artist_info = Artists.get_artist_info!(artist_id)
assert ArtistInfo.lastfm_tags(artist_info) == []
end end
test "filters out tags with count below 2", %{artist_id: artist_id} do test "filters out tags with count below 2", %{artist_id: artist_id} do