diff --git a/app/models/apple/publisher.rb b/app/models/apple/publisher.rb index bdf70aae7..4464d5819 100644 --- a/app/models/apple/publisher.rb +++ b/app/models/apple/publisher.rb @@ -235,8 +235,9 @@ def wait_for_asset_state(eps) (waiting_timed_out, _) = Apple::Episode.wait_for_asset_state(api, eps) if waiting_timed_out - attempts = eps.max { |ep| ep.apple_episode_delivery_status.asset_processing_attempts } - raise "Timed out waiting for asset state. #{attempts} attempts so far" + attempts = eps.map { |ep| ep.apple_episode_delivery_status.asset_processing_attempts }.max + Rails.logger.info("Timed out waiting for asset state", {attempts: attempts, episode_count: eps.length}) + raise "Timed out waiting for asset state" end end end diff --git a/test/models/apple/publisher_test.rb b/test/models/apple/publisher_test.rb index 77cbcedb2..b79fe75a9 100644 --- a/test/models/apple/publisher_test.rb +++ b/test/models/apple/publisher_test.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require "test_helper" describe Apple::Publisher do @@ -13,6 +11,8 @@ Apple::Publisher.new(api: apple_api, public_feed: public_feed, private_feed: private_feed) end + let(:publisher) { apple_publisher } + before do stub_request(:get, "https://api.podcastsconnect.apple.com/v1/countriesAndRegions?limit=200") .to_return(status: 200, body: json_file(:apple_countries_and_regions), headers: {}) @@ -404,6 +404,32 @@ end end + it "logs a timeout message with correct information" do + eps = [ + OpenStruct.new( + podcast_delivery_files: [OpenStruct.new(api_marked_as_uploaded?: true)], + apple_episode_delivery_status: OpenStruct.new( + increment_asset_wait: nil, + asset_processing_attempts: 3 + ) + ) + ] * 2 # Create two identical episode structures + + log_message = nil + Rails.logger.stub :tagged, nil do + Rails.logger.stub :info, ->(msg, data) { log_message = [msg, data] } do + Apple::Episode.stub :wait_for_asset_state, [true, nil] do + publisher.wait_for_asset_state(eps) + rescue RuntimeError + # Ignore the exception for this test + end + end + end + + assert_equal "Timed out waiting for asset state", log_message[0] + assert_equal({attempts: 3, episode_count: 2}, log_message[1]) + end + it "should raise an error when wait times out" do episode1.apple_episode_delivery_status.update!(asset_processing_attempts: 3)