Add async job to fetch artist image

This commit is contained in:
Claudio Ortolina
2025-04-27 21:20:12 +01:00
parent 3d3e758a7a
commit f5b783bdff
2 changed files with 19 additions and 0 deletions
+9
View File
@@ -100,6 +100,15 @@ defmodule MusicLibrary.Artists do
|> BackgroundRepo.insert()
end
def fetch_image_async(artist_id) do
meta = %{}
params = %{"id" => artist_id}
params
|> Worker.FetchArtistImage.new(meta: meta)
|> BackgroundRepo.insert()
end
def get_image(artist_id) do
q =
from ai in ArtistInfo,
@@ -0,0 +1,10 @@
defmodule MusicLibrary.Worker.FetchArtistImage do
use Oban.Worker, queue: :default, max_attempts: 3
@impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => artist_id}}) do
with {:ok, _artist_info} <- MusicLibrary.Artists.fetch_image(artist_id) do
:ok
end
end
end