Skip to content

Commit

Permalink
Add job to republish public feed when adding Apple feed
Browse files Browse the repository at this point in the history
  • Loading branch information
kookster committed Sep 19, 2024
1 parent 13cbcc4 commit 7558df0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
17 changes: 17 additions & 0 deletions app/jobs/publish_public_feed_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "builder"

class PublishPublicFeedJob < ApplicationJob
queue_as :feeder_publishing

include PodcastsHelper

attr_writer :publish_feed_job

def perform(podcast)
publish_feed_job.save_file(podcast, podcast.public_feed)
end

def publish_feed_job
@publish_feed_job ||= PublishFeedJob.new
end
end
6 changes: 3 additions & 3 deletions app/models/feeds/apple_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Feeds::AppleSubscription < Feed

after_initialize :set_defaults

after_create :publish_feeds
after_create :republish_public_feed

has_one :apple_config, class_name: "::Apple::Config", dependent: :destroy, autosave: true, validate: true, inverse_of: :feed

Expand All @@ -33,8 +33,8 @@ def self.model_name
Feed.model_name
end

def publish_feeds
podcast&.publish!
def republish_public_feed
PublishPublicFeedJob.perform_later(podcast)
end

def unchanged_defaults
Expand Down
17 changes: 17 additions & 0 deletions test/jobs/publish_public_feed_job_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "test_helper"

describe PublishPublicFeedJob do
let(:podcast) { create(:podcast) }

let(:job) { PublishPublicFeedJob.new }

describe "saving the public rss file" do
let(:stub_client) { Aws::S3::Client.new(stub_responses: true) }

it "can call save_file on PublishFeedJob" do
job.publish_feed_job.stub(:s3_client, stub_client) do
refute_nil job.perform(podcast)
end
end
end
end

0 comments on commit 7558df0

Please sign in to comment.