Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple retry uploads #707

Merged
merged 11 commits into from
Jul 25, 2023
6 changes: 3 additions & 3 deletions app/models/apple/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def drafting?
apple_json&.dig("attributes", "publishingState") == "DRAFTING"
end

def apple_upload_complete?
feeder_episode.apple_podcast_container.skip_delivery?
def container_upload_complete?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cavis I hope this clarifies. I renamed to emphasize the container upload semantics here. We need to deliver the audio file (Delivery, DeliveryFiles) and the container upload (PodcastContaner files attribute) will be complete (a file marked present).

The overall Apple::Episode#synced_with_apple? covers the rest. That method filters the episodes that go into the publishing routines in Apple::Publisher.

feeder_episode.apple_podcast_container.container_upload_satisfied?
end

def audio_asset_vendor_id
Expand Down Expand Up @@ -437,7 +437,7 @@ def reset_for_upload!
end

def synced_with_apple?
audio_asset_state_success? && apple_upload_complete? && !drafting?
audio_asset_state_success? && container_upload_complete? && !drafting?
end

def waiting_for_asset_state?
Expand Down
4 changes: 4 additions & 0 deletions app/models/apple/podcast_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ def delivery_settled?
end

def skip_delivery?
container_upload_satisfied?
end

def container_upload_satisfied?
# Sets us up for a retry if something prevented the audio from being
# marked as uploaded and then processed and validated. Assuming that we
# get to that point and the audio is still missing, we should be able to
Expand Down
2 changes: 1 addition & 1 deletion app/models/apple/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def mark_delivery_files_uploaded!(eps)

def publish_drafting!(eps)
Rails.logger.tagged("##{__method__}") do
eps = eps.select { |ep| ep.drafting? && ep.apple_upload_complete? }
eps = eps.select { |ep| ep.drafting? && ep.container_upload_complete? }

res = Apple::Episode.publish(api, show, eps)
Rails.logger.info("Published #{res.length} drafting episodes.")
Expand Down
2 changes: 1 addition & 1 deletion test/models/apple/publisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

describe "#publish_drafting!" do
it "should call the episode publish drafting class method" do
ep = OpenStruct.new(drafting?: true, apple_upload_complete?: true)
ep = OpenStruct.new(drafting?: true, container_upload_complete?: true)
mock = Minitest::Mock.new
mock.expect(:call, [], [apple_publisher.api, apple_publisher.show, [ep]])

Expand Down