Introduce a Req.RateLimiter module to fix API rate limit issues
This commit is contained in:
@@ -10,6 +10,7 @@ defmodule MusicLibrary.Application do
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
_ = Assets.Cache.new()
|
||||
_ = Req.RateLimiter.new()
|
||||
|
||||
children = [
|
||||
MusicLibrary.Vault,
|
||||
|
||||
@@ -3,10 +3,6 @@ defmodule MusicLibrary.Worker.ArtistRefreshDiscogsData do
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"id" => artist_info_id}}) do
|
||||
result = MusicLibrary.Artists.refresh_discogs_data(artist_info_id)
|
||||
|
||||
Process.sleep(Discogs.api_cooldown())
|
||||
|
||||
result
|
||||
MusicLibrary.Artists.refresh_discogs_data(artist_info_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,10 +3,6 @@ defmodule MusicLibrary.Worker.ArtistRefreshMusicBrainzData do
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"id" => artist_info_id}}) do
|
||||
result = MusicLibrary.Artists.refresh_musicbrainz_data(artist_info_id)
|
||||
|
||||
Process.sleep(MusicBrainz.api_cooldown())
|
||||
|
||||
result
|
||||
MusicLibrary.Artists.refresh_musicbrainz_data(artist_info_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,14 +3,9 @@ defmodule MusicLibrary.Worker.FetchArtistLastFmData do
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"id" => artist_id}}) do
|
||||
result =
|
||||
case MusicLibrary.Artists.fetch_lastfm_data(artist_id) do
|
||||
{:ok, _artist_info} -> :ok
|
||||
error -> error
|
||||
end
|
||||
|
||||
Process.sleep(LastFm.api_cooldown())
|
||||
|
||||
result
|
||||
case MusicLibrary.Artists.fetch_lastfm_data(artist_id) do
|
||||
{:ok, _artist_info} -> :ok
|
||||
error -> error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,13 +5,8 @@ defmodule MusicLibrary.Worker.RecordRefreshMusicBrainzData do
|
||||
def perform(%Oban.Job{args: %{"id" => record_id}}) do
|
||||
record = MusicLibrary.Records.get_record!(record_id)
|
||||
|
||||
result =
|
||||
with {:ok, updated_record} <- MusicLibrary.Records.refresh_musicbrainz_data(record) do
|
||||
MusicLibrary.Records.notify_update(updated_record)
|
||||
end
|
||||
|
||||
Process.sleep(MusicBrainz.api_cooldown())
|
||||
|
||||
result
|
||||
with {:ok, updated_record} <- MusicLibrary.Records.refresh_musicbrainz_data(record) do
|
||||
MusicLibrary.Records.notify_update(updated_record)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user