From e12ae3cffc2f627c587b8065ad62e680c35cb369 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 9 Oct 2024 11:39:20 -0500 Subject: [PATCH 01/12] Add new retry state --- app/jobs/publish_feed_job.rb | 6 ++--- app/models/publishing_pipeline_state.rb | 11 ++++++--- test/models/publishing_pipeline_state_test.rb | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index 75eb2bc85..fe3f05879 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -47,9 +47,9 @@ def publish_rss(podcast, feed) end def handle_apple_timeout_error(podcast, error, raise_error: true) - PublishingPipelineState.error!(podcast) - Rails.logger.error("Asset processing timeout", {podcast_id: podcast.id, error: error.message, backtrace: error&.backtrace&.join("\n")}) - raise error + PublishingPipelineState.retry!(podcast) + Rails.logger.error("Asset processing timeout", {podcast_id: podcast.id, error: e.message, backtrace: e.backtrace.join("\n")}) + # TODO Does not re-raise the error end def handle_apple_error(podcast, error) diff --git a/app/models/publishing_pipeline_state.rb b/app/models/publishing_pipeline_state.rb index 3fcb5baf7..5be1712bc 100644 --- a/app/models/publishing_pipeline_state.rb +++ b/app/models/publishing_pipeline_state.rb @@ -1,6 +1,6 @@ class PublishingPipelineState < ApplicationRecord - TERMINAL_STATUSES = [:complete, :error, :expired].freeze - TERMINAL_FAILURE_STATUSES = [:error, :expired].freeze + TERMINAL_STATUSES = [:complete, :error, :expired, :retry].freeze + TERMINAL_FAILURE_STATUSES = [:error, :expired, :retry].freeze UNIQUE_STATUSES = TERMINAL_STATUSES + [:created, :started] # Handle the max timout for a publishing pipeline: Pub RSS job + Pub Apple job + a few extra minutes of flight @@ -53,7 +53,8 @@ class PublishingPipelineState < ApplicationRecord :error, :expired, :error_apple, - :error_rss + :error_rss, + :retry ] validate :podcast_ids_match @@ -170,6 +171,10 @@ def self.expire!(podcast) state_transition(podcast, :expired) end + def self.retry!(podcast) + state_transition(podcast, :retry) + end + def self.expire_pipelines! Podcast.with_deleted.where(id: expired_pipelines.select(:podcast_id)).each do |podcast| Rails.logger.tagged("PublishingPipeLineState.expire_pipelines!", "Podcast:#{podcast.id}") do diff --git a/test/models/publishing_pipeline_state_test.rb b/test/models/publishing_pipeline_state_test.rb index 820524a6d..b1f25777d 100644 --- a/test/models/publishing_pipeline_state_test.rb +++ b/test/models/publishing_pipeline_state_test.rb @@ -273,6 +273,29 @@ end end + describe "retry!" do + it 'sets the status to "retry"' do + pqi = nil + PublishFeedJob.stub_any_instance(:save_file, nil) do + PublishFeedJob.stub_any_instance(:publish_apple, ->(*args) { raise Apple::AssetStateTimeoutError.new([]) }) do + pqi = PublishingQueueItem.ensure_queued!(podcast) + PublishingPipelineState.attempt!(podcast, perform_later: false) + end + end + + assert_equal ["created", "started", "retry"].sort, PublishingPipelineState.where(podcast: podcast).map(&:status).sort + assert_equal "retry", pqi.reload.last_pipeline_state + + # it retries + PublishingPipelineState.retry_failed_pipelines! + assert_equal ["created", "started", "retry", "created"].sort, PublishingPipelineState.where(podcast: podcast).map(&:status).sort + res_pqi = PublishingQueueItem.current_unfinished_item(podcast) + + assert res_pqi.id > pqi.id + assert_equal "created", res_pqi.last_pipeline_state + end + end + describe "complete!" do it 'sets the status to "complete"' do PublishFeedJob.stub_any_instance(:save_file, nil) do From 7d479847f544fa4bfcb2604025e5f730d59d51c2 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 9 Oct 2024 13:28:55 -0500 Subject: [PATCH 02/12] Vary log level output by error count --- app/jobs/publish_feed_job.rb | 14 +++-- app/models/apple/asset_state_timeout_error.rb | 11 ++++ test/jobs/publish_feed_job_test.rb | 53 +++++++++++++------ 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index fe3f05879..20fe83b5d 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -46,10 +46,18 @@ def publish_rss(podcast, feed) handle_rss_error(podcast, feed, e) end - def handle_apple_timeout_error(podcast, error, raise_error: true) + def handle_apple_timeout_error(podcast, asset_timeout_error) PublishingPipelineState.retry!(podcast) - Rails.logger.error("Asset processing timeout", {podcast_id: podcast.id, error: e.message, backtrace: e.backtrace.join("\n")}) - # TODO Does not re-raise the error + Rails.logger.send(asset_timeout_error.log_level) do + [ + "Asset processing timeout", + { + podcast_id: podcast.id, + error: asset_timeout_error.message, + backtrace: asset_timeout_error&.backtrace&.join("\n") + } + ] + end end def handle_apple_error(podcast, error) diff --git a/app/models/apple/asset_state_timeout_error.rb b/app/models/apple/asset_state_timeout_error.rb index 82e0b19b7..1b62134ba 100644 --- a/app/models/apple/asset_state_timeout_error.rb +++ b/app/models/apple/asset_state_timeout_error.rb @@ -12,5 +12,16 @@ def initialize(episodes) def episode_ids episodes.map(&:feeder_id) end + + def log_level + case attempts + when 0..4 + :warn + when 5 + :error + else + :fatal + end + end end end diff --git a/test/jobs/publish_feed_job_test.rb b/test/jobs/publish_feed_job_test.rb index 6264c3c05..11df4cc68 100644 --- a/test/jobs/publish_feed_job_test.rb +++ b/test/jobs/publish_feed_job_test.rb @@ -105,12 +105,16 @@ end describe "publishing to apple" do + let(:podcast) { create(:podcast) } + let(:public_feed) { podcast.default_feed } + let(:private_feed) { create(:apple_feed, podcast: podcast) } let(:apple_feed) { private_feed } - let(:apple_config) { podcast.apple_config } + let(:apple_config) { private_feed.apple_config } + let(:apple_publisher) { apple_config.build_publisher } before do assert private_feed.persisted? - assert podcast.reload.apple_config.present? + assert apple_config.persisted? end describe "#perform" do @@ -163,25 +167,40 @@ PublishingQueueItem.create!(podcast: feed.podcast) end - it "raises an error if the apple publishing fails" do - assert apple_feed.apple_config.present? - assert apple_feed.apple_config.publish_enabled - - PublishAppleJob.stub(:do_perform, ->(*, **) { raise "some apple error" }) do - assert_raises(RuntimeError) { PublishingPipelineState.attempt!(feed.podcast, perform_later: false) } + let(:episode1) { build(:uploaded_apple_episode, show: apple_publisher.show) } + let(:episode2) { build(:uploaded_apple_episode, show: apple_publisher.show) } + let(:episodes) { [episode1, episode2] } - assert_equal ["created", "started", "error", "error_apple"].sort, PublishingPipelineState.where(podcast: feed.podcast).latest_pipelines.pluck(:status).sort - end - end - - it "raises an error if the apple publishing times out" do + it "logs message if the apple publishing times out" do assert apple_feed.apple_config.present? assert apple_feed.apple_config.publish_enabled - PublishAppleJob.stub(:do_perform, ->(*, **) { raise Apple::AssetStateTimeoutError.new([]) }) do - assert_raises(Apple::AssetStateTimeoutError) { PublishingPipelineState.attempt!(feed.podcast, perform_later: false) } - - assert_equal ["created", "started", "error", "error_apple"].sort, PublishingPipelineState.where(podcast: feed.podcast).latest_pipelines.pluck(:status).sort + expected_level_for_timeouts = [ + [0, 40], + [1, 40], + [2, 40], + [3, 40], + [4, 40], + [5, 50], + [6, 60] + ] + + expected_level_for_timeouts.each do |(attempts, level)| + # simulate a episode waiting n times + episodes.first.apple_episode_delivery_status.update(asset_processing_attempts: attempts) + + PublishAppleJob.stub(:do_perform, ->(*, **) { raise Apple::AssetStateTimeoutError.new(episodes) }) do + lines = capture_json_logs do + PublishingQueueItem.ensure_queued!(feed.podcast) + PublishingPipelineState.attempt!(feed.podcast, perform_later: false) + end + + log = lines.find { |l| l["msg"].include?("Asset processing timeout") } + assert log.present? + assert_equal level, log["level"] + + assert_equal ["created", "started", "retry", "error_apple"].sort, PublishingPipelineState.where(podcast: feed.podcast).latest_pipelines.pluck(:status).sort + end end end end From 977c22ea27c5135c2613abd7fb1447fe99467a9d Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 28 Oct 2024 14:13:44 -0500 Subject: [PATCH 03/12] Reset the asset processing count also --- app/models/concerns/apple_delivery.rb | 2 +- test/models/episode_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/apple_delivery.rb b/app/models/concerns/apple_delivery.rb index 4d7c97656..1b11bc245 100644 --- a/app/models/concerns/apple_delivery.rb +++ b/app/models/concerns/apple_delivery.rb @@ -40,7 +40,7 @@ def apple_needs_delivery? end def apple_needs_delivery! - apple_update_delivery_status(delivered: false) + apple_update_delivery_status(delivered: false, asset_processing_attempts: 0) end def apple_has_delivery! diff --git a/test/models/episode_test.rb b/test/models/episode_test.rb index 0ef8f4d8e..22b7ee468 100644 --- a/test/models/episode_test.rb +++ b/test/models/episode_test.rb @@ -474,6 +474,7 @@ # now set it to true episode.apple_needs_delivery! assert episode.apple_needs_delivery? + assert episode.apple_episode_delivery_status.asset_processing_attempts == 0 end end From 44ee4106d66548d6a45d1438c937fcb1d2a6b63c Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 28 Oct 2024 14:16:46 -0500 Subject: [PATCH 04/12] Fixup signature --- app/models/concerns/apple_delivery.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/apple_delivery.rb b/app/models/concerns/apple_delivery.rb index 1b11bc245..42bd7330b 100644 --- a/app/models/concerns/apple_delivery.rb +++ b/app/models/concerns/apple_delivery.rb @@ -48,6 +48,6 @@ def apple_has_delivery! end def measure_asset_processing_duration - Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses).first + Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses, Time.now.utc).first end end From 1cd5d6152a3727f1097ffd57ceac360d231f1af9 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 28 Oct 2024 14:18:30 -0500 Subject: [PATCH 05/12] Lint --- app/models/apple/episode_delivery_status.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/apple/episode_delivery_status.rb b/app/models/apple/episode_delivery_status.rb index aafc34c39..f05da046d 100644 --- a/app/models/apple/episode_delivery_status.rb +++ b/app/models/apple/episode_delivery_status.rb @@ -47,7 +47,7 @@ def self.measure_asset_processing_duration(apple_episode_delivery_statuses, rela return [nil, measure_asset_processing_duration(statuses, last_status.created_at)].flatten unless last_status&.asset_processing_attempts.to_i.positive? - end_status = while status = statuses.shift + end_status = while (status = statuses.shift) break status if status.asset_processing_attempts.to_i.zero? end From fab5c26608d8e585d482faa853341050f984153b Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 4 Nov 2024 12:22:50 -0600 Subject: [PATCH 06/12] Stub at a deeper level --- test/models/publishing_pipeline_state_test.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/models/publishing_pipeline_state_test.rb b/test/models/publishing_pipeline_state_test.rb index b1f25777d..176a9b9f0 100644 --- a/test/models/publishing_pipeline_state_test.rb +++ b/test/models/publishing_pipeline_state_test.rb @@ -274,21 +274,33 @@ end describe "retry!" do + let(:podcast) { create(:podcast) } + let(:public_feed) { podcast.default_feed } + let(:private_feed) { create(:apple_feed, podcast: podcast) } + let(:apple_feed) { private_feed } + let(:apple_config) { private_feed.apple_config } + let(:apple_publisher) { apple_config.build_publisher } + it 'sets the status to "retry"' do + episode = build(:uploaded_apple_episode, show: apple_publisher.show) + + # it does not trigger an exception + episode.apple_episode_delivery_status.update(asset_processing_attempts: 1) + pqi = nil PublishFeedJob.stub_any_instance(:save_file, nil) do - PublishFeedJob.stub_any_instance(:publish_apple, ->(*args) { raise Apple::AssetStateTimeoutError.new([]) }) do + PublishAppleJob.stub(:do_perform, ->(*args) { raise Apple::AssetStateTimeoutError.new([episode]) }) do pqi = PublishingQueueItem.ensure_queued!(podcast) PublishingPipelineState.attempt!(podcast, perform_later: false) end end - assert_equal ["created", "started", "retry"].sort, PublishingPipelineState.where(podcast: podcast).map(&:status).sort + assert_equal ["created", "started", "error_apple", "retry"], PublishingPipelineState.where(podcast: podcast).order(:id).pluck(:status) assert_equal "retry", pqi.reload.last_pipeline_state # it retries PublishingPipelineState.retry_failed_pipelines! - assert_equal ["created", "started", "retry", "created"].sort, PublishingPipelineState.where(podcast: podcast).map(&:status).sort + assert_equal ["created", "started", "error_apple", "retry", "created"], PublishingPipelineState.where(podcast: podcast).order(:id).pluck(:status) res_pqi = PublishingQueueItem.current_unfinished_item(podcast) assert res_pqi.id > pqi.id From f86186263e63c4b89ff24cddb7f44fc0bcc8ee74 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 4 Nov 2024 12:24:15 -0600 Subject: [PATCH 07/12] CI stray --- test/models/concerns/apple_delivery_test.rb | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/models/concerns/apple_delivery_test.rb diff --git a/test/models/concerns/apple_delivery_test.rb b/test/models/concerns/apple_delivery_test.rb new file mode 100644 index 000000000..285fdf858 --- /dev/null +++ b/test/models/concerns/apple_delivery_test.rb @@ -0,0 +1,78 @@ +require "test_helper" + +class AppleDeliveryTest < ActiveSupport::TestCase + let(:episode) { create(:episode_with_media) } + + describe "#apple_episode" do + let(:episode) { create(:episode) } + it "gets nil for no apple episode" do + assert_nil episode.apple_episode + end + end + + describe "#apple_needs_delivery?" do + let(:episode) { create(:episode) } + it "is true by default" do + refute episode.apple_episode_delivery_status.persisted? + assert episode.apple_needs_delivery? + end + + it "can be set to false" do + episode.apple_has_delivery! + refute episode.apple_needs_delivery? + end + + it "can be set to true" do + episode.apple_has_delivery! + refute episode.apple_needs_delivery? + + # now set it to true + episode.apple_needs_delivery! + assert episode.apple_needs_delivery? + end + end + + describe "#increment_asset_wait" do + let(:episode) { create(:episode) } + + it "creates a new status with incremented asset_processing_attempts" do + assert_difference -> { episode.apple_episode_delivery_statuses.count }, 1 do + new_status = episode.apple_status.increment_asset_wait + assert_equal 1, new_status.asset_processing_attempts + end + end + + it "increments existing asset_processing_attempts" do + create(:apple_episode_delivery_status, episode: episode, asset_processing_attempts: 2) + new_status = episode.apple_status.increment_asset_wait + assert_equal 3, new_status.asset_processing_attempts + end + + it "maintains other attributes when incrementing" do + create(:apple_episode_delivery_status, + episode: episode, + delivered: true, + source_url: "http://example.com/audio.mp3", + asset_processing_attempts: 1) + + new_status = episode.apple_status.increment_asset_wait + assert_equal 2, new_status.asset_processing_attempts + assert new_status.delivered + assert_equal "http://example.com/audio.mp3", new_status.source_url + end + + it "creates a new status with asset_processing_attempts set to 1 if no previous status exists" do + episode.apple_episode_delivery_statuses.destroy_all + assert_difference -> { episode.apple_episode_delivery_statuses.count }, 1 do + new_status = episode.apple_status.increment_asset_wait + assert_equal 1, new_status.asset_processing_attempts + end + end + + it "returns the new status" do + result = episode.apple_status.increment_asset_wait + assert_instance_of Apple::EpisodeDeliveryStatus, result + assert_equal episode.apple_episode_delivery_statuses.last, result + end + end +end From ca4e787e3596a3fed05221b18c990e9d9d262438 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 4 Nov 2024 12:29:55 -0600 Subject: [PATCH 08/12] Fixup merge --- app/jobs/publish_feed_job.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index b2d585e28..2703864a3 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -26,15 +26,6 @@ def perform(podcast, pub_item) PublishingPipelineState.settle_remaining!(podcast) end - def handle_error(podcast, error) - PublishingPipelineState.error!(podcast) - # Two error log lines here. - # 1) the error message and backtrace: - Rails.logger.error("Error publishing podcast", {podcast_id: podcast.id, error: error.message, backtrace: error&.backtrace&.join("\n")}) - # 2) The second is from the job handler, which logs an error when this excetion is raised: - raise error - end - def publish_apple(podcast, feed) return unless feed.publish_to_apple? From 3ded83dc6715a46f0ccd5153c2a40b2484bdac2c Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 11 Nov 2024 12:19:24 -0600 Subject: [PATCH 09/12] Remove debugging tools --- app/models/apple/episode_delivery_status.rb | 55 ++------------------- app/models/concerns/apple_delivery.rb | 2 +- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/app/models/apple/episode_delivery_status.rb b/app/models/apple/episode_delivery_status.rb index f05da046d..24bf5bcfd 100644 --- a/app/models/apple/episode_delivery_status.rb +++ b/app/models/apple/episode_delivery_status.rb @@ -2,61 +2,16 @@ module Apple class EpisodeDeliveryStatus < ApplicationRecord belongs_to :episode, -> { with_deleted }, class_name: "::Episode" - def self.change_log(apple_episode_delivery_statuses) - return [] unless apple_episode_delivery_statuses&.any? - - statuses = apple_episode_delivery_statuses.to_a - changes = [] - - tracked_attributes = column_names - ["id", "created_at"] - - latest_values = {} - - statuses.reverse_each do |status| - tracked_attributes.each do |attr| - value = status.send(attr) - - # Only record the change if we haven't seen this attribute before - # or if the value is different from the most recent one - if !latest_values.key?(attr) || latest_values[attr] != value - latest_values[attr] = value - - # Format the change message - message = format_change_message(attr, value, status.created_at) - changes.unshift(message) unless message.nil? - end - end - end - - changes - end - - def self.format_change_message(attribute, value, timestamp) - return nil if value.nil? - - formatted_time = timestamp.strftime("%Y-%m-%d %H:%M:%S") - "#{formatted_time}: #{attribute.humanize} changed to #{value}" - end - - def self.measure_asset_processing_duration(apple_episode_delivery_statuses, relative_timestamp) - return [] unless apple_episode_delivery_statuses&.any? - + def self.measure_asset_processing_duration(apple_episode_delivery_statuses) statuses = apple_episode_delivery_statuses.to_a last_status = statuses.shift + return nil unless last_status&.asset_processing_attempts.to_i.positive? - return [nil, measure_asset_processing_duration(statuses, last_status.created_at)].flatten unless last_status&.asset_processing_attempts.to_i.positive? - - end_status = while (status = statuses.shift) - break status if status.asset_processing_attempts.to_i.zero? - end - - return [nil].flatten unless end_status + start_status = statuses.find { |status| status.asset_processing_attempts.to_i.zero? } + return nil unless start_status - [ - relative_timestamp - end_status.created_at, - measure_asset_processing_duration(statuses, end_status.created_at) - ].flatten + Time.now - start_status.created_at end def self.update_status(episode, attrs) diff --git a/app/models/concerns/apple_delivery.rb b/app/models/concerns/apple_delivery.rb index f76e2a6e4..3bf177e79 100644 --- a/app/models/concerns/apple_delivery.rb +++ b/app/models/concerns/apple_delivery.rb @@ -48,7 +48,7 @@ def apple_has_delivery! end def measure_asset_processing_duration - Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses, Time.now.utc).first + Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses) end def apple_prepare_for_delivery! From f088b0d4cdd20bb7881a4b7391b8cdf8fc729364 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 11 Nov 2024 12:24:49 -0600 Subject: [PATCH 10/12] Restore new relic logging --- app/jobs/publish_feed_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index 2703864a3..13bc6c2b9 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -36,6 +36,7 @@ def publish_apple(podcast, feed) # Not strictly a 'fail state' because we want to retry this job PublishingPipelineState.error_apple!(podcast) Rails.logger.send(e.log_level, e.message, {podcast_id: podcast.id}) + NewRelic::Agent.notice_error(e) raise e if podcast.apple_config.sync_blocks_rss rescue => e if podcast.apple_config.sync_blocks_rss From f09a113e309095b50d76174c8ef4bd964cdbe283 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 11 Nov 2024 12:27:12 -0600 Subject: [PATCH 11/12] Refactor for clarity --- app/jobs/publish_feed_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index 13bc6c2b9..92093fba3 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -66,7 +66,7 @@ def fail_state(podcast, type, error) when "rss" then [:error_rss!, :warn, true] when "apple_timeout" level = apple_timeout_log_level(error) - [:retry!, level, level == :fatal || level == :error] + [:retry!, level, %i[error fatal].include?(level)] when "error" then [:error!, :error, true] end From 552f2fa5b932096a6714538b472afba7cb586d5d Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Mon, 11 Nov 2024 13:27:20 -0600 Subject: [PATCH 12/12] Extract helper --- app/jobs/publish_feed_job.rb | 20 +++++++++++++------ app/models/apple/asset_state_timeout_error.rb | 4 ++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/jobs/publish_feed_job.rb b/app/jobs/publish_feed_job.rb index 92093fba3..50a3f63c7 100644 --- a/app/jobs/publish_feed_job.rb +++ b/app/jobs/publish_feed_job.rb @@ -59,20 +59,28 @@ def apple_timeout_log_level(error) error.try(:log_level) || :error end + def should_raise?(error) + if error.respond_to?(:raise_publishing_error?) + error.raise_publishing_error? + else + true + end + end + def fail_state(podcast, type, error) - (pipeline_method, log_level, raise_exception) = + (pipeline_method, log_level) = case type - when "apple" then [:error_apple!, :warn, true] - when "rss" then [:error_rss!, :warn, true] + when "apple" then [:error_apple!, :warn] + when "rss" then [:error_rss!, :warn] when "apple_timeout" level = apple_timeout_log_level(error) - [:retry!, level, %i[error fatal].include?(level)] - when "error" then [:error!, :error, true] + [:retry!, level] + when "error" then [:error!, :error] end PublishingPipelineState.public_send(pipeline_method, podcast) Rails.logger.send(log_level, error.message, {podcast_id: podcast.id}) - raise error if raise_exception + raise error if should_raise?(error) end def save_file(podcast, feed, options = {}) diff --git a/app/models/apple/asset_state_timeout_error.rb b/app/models/apple/asset_state_timeout_error.rb index 1b62134ba..e90b7c10f 100644 --- a/app/models/apple/asset_state_timeout_error.rb +++ b/app/models/apple/asset_state_timeout_error.rb @@ -13,6 +13,10 @@ def episode_ids episodes.map(&:feeder_id) end + def raise_publishing_error? + %i[error fatal].include?(log_level) + end + def log_level case attempts when 0..4