Add async job to fetch artist image
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user