From 1ca1dcf0f3db38693d1f933c8d2a2a9faeccf4ee Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 11 Aug 2025 11:59:44 +0300 Subject: [PATCH] Fix signature of LastFm.Feed.update/1 --- lib/last_fm/feed.ex | 4 +++- lib/last_fm/worker/backfill_scrobbled_tracks.ex | 4 ++-- test/last_fm/feed_test.exs | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/last_fm/feed.ex b/lib/last_fm/feed.ex index 5c76c53e..3953fa98 100644 --- a/lib/last_fm/feed.ex +++ b/lib/last_fm/feed.ex @@ -21,7 +21,7 @@ defmodule LastFm.Feed do :last_fm_data ] - @spec update([LastFm.Track.t()]) :: :ok | no_return + @spec update([LastFm.Track.t()]) :: {:ok, non_neg_integer()} | no_return def update(tracks) do track_params = tracks @@ -37,6 +37,8 @@ defmodule LastFm.Feed do MusicLibrary.ScrobbleRules.apply_all_rules() Phoenix.PubSub.broadcast(LastFm.PubSub, "feed:update", %{track_count: count}) + + {:ok, count} end @spec all_tracks(non_neg_integer()) :: [LastFm.Track.t()] diff --git a/lib/last_fm/worker/backfill_scrobbled_tracks.ex b/lib/last_fm/worker/backfill_scrobbled_tracks.ex index 6f5f7852..ff38ba5f 100644 --- a/lib/last_fm/worker/backfill_scrobbled_tracks.ex +++ b/lib/last_fm/worker/backfill_scrobbled_tracks.ex @@ -12,14 +12,14 @@ defmodule LastFm.Worker.BackfillScrobbledTracks do # use the returning count to determine if we reached the end of the backfilling # process. case LastFm.Import.batch(to_uts: to_uts, limit: @batch_size) do - {@batch_size, nil} -> + {:ok, @batch_size} -> next_to_uts = LastFm.lowest_scrobbled_at_uts() %{"to_uts" => next_to_uts} |> new(schedule_in: @backfill_delay) |> BackgroundRepo.insert() - {other_count, nil} when is_integer(other_count) -> + {:ok, _other_count} -> :ok error -> diff --git a/test/last_fm/feed_test.exs b/test/last_fm/feed_test.exs index 28fc3d4e..2a56520a 100644 --- a/test/last_fm/feed_test.exs +++ b/test/last_fm/feed_test.exs @@ -40,16 +40,16 @@ defmodule LastFm.FeedTest do test "it stores the track and broadcasts the updated track count" do :ok = Feed.subscribe() - :ok = Feed.update([@track_two, @track_one]) + assert {:ok, 2} == Feed.update([@track_two, @track_one]) assert_receive %{track_count: 2} # Tracks have already been inserted, count of new tracks is 0 - :ok = Feed.update([@track_two, @track_one]) + assert {:ok, 0} == Feed.update([@track_two, @track_one]) assert_receive %{track_count: 0} end test "it returns tracks in descending order of scrobble" do - :ok = Feed.update([@track_two, @track_one]) + assert {:ok, 2} == Feed.update([@track_two, @track_one]) track_two_scrobbled_at_uts = @track_two.scrobbled_at_uts track_one_scrobbled_at_uts = @track_one.scrobbled_at_uts