Discard worker when no wikipedia entry is present

This commit is contained in:
Claudio Ortolina
2026-04-01 08:52:28 +01:00
parent e3a6c0563b
commit 553ad2bbb9
2 changed files with 38 additions and 0 deletions
@@ -9,6 +9,9 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do
# refresh_lastfm_data returns {:ok, _} even on API errors, so it won't block embeddings
MusicLibrary.Artists.refresh_lastfm_data(artist_id)
MusicLibrary.Records.regenerate_artist_embeddings(artist_id)
else
{:error, :no_english_wikipedia} -> {:discard, :no_english_wikipedia}
error -> error
end
end
end
@@ -10,6 +10,41 @@ defmodule MusicLibrary.Worker.FetchArtistInfoTest do
@steven_wilson_mbid "3a51b862-0144-40f6-aa17-6aaeefea29d9"
describe "perform/1" do
test "discards when artist has no English Wikipedia page" do
_record =
record(%{
artists: [
%{
name: "Steven Wilson",
musicbrainz_id: @steven_wilson_mbid,
sort_name: "Wilson, Steven",
joinphrase: ""
}
]
})
Req.Test.stub(MusicBrainz.API, fn conn ->
Req.Test.json(conn, MusicBrainz.Fixtures.Artist.get_artist())
end)
Req.Test.stub(Discogs.API, fn conn ->
case conn.request_path do
"/artists/" <> _ ->
Req.Test.json(conn, Discogs.Fixtures.Artist.get_artist())
_ ->
Plug.Conn.send_resp(conn, 200, Discogs.Fixtures.Artist.image_data())
end
end)
Req.Test.stub(Wikipedia.API, fn conn ->
Req.Test.json(conn, Wikipedia.Fixtures.wikidata_response_no_enwiki())
end)
assert {:discard, :no_english_wikipedia} =
perform_job(FetchArtistInfo, %{"id" => @steven_wilson_mbid})
end
test "fetches and stores artist info from all sources" do
# Create a record with the artist musicbrainz_id matching the fixture
_record =